我有这样的字符串: 我的代码是:
$html = new DOMDocument();
$html->loadHTML($message);
$items = $html->getElementsByTagName('div');
foreach($items as $item) {
$headline = array();
if($item->childNodes->length) {
foreach($item->childNodes as $i) {
$headline[$i->nodeName] = $i->nodeValue;
}
}
$headlines[] = $headline;
}
foreach ($headlines as $key => $value) {
$quote = $value['blockquote'];
}.
print_r($quote);
output ="this is your message.
Your Ticket ID = :68
Response ID = :45check that if its not contains any error."
我想获得Ticket ID =:68
和Response id =:45
。
当我打印blockquote时,我得到了上面的文字。现在我想得到我的机票ID和响应ID,但不知道怎么做?
答案 0 :(得分:0)
您可以使用正则表达式实现此目的
$var ="this is your message.
Your Ticket ID = :68
Response ID = :45check that if its not contains any error.";
$match = array();
$ticketID = '';
$responseID = '';
preg_match('/Your Ticket ID = :([0-9]+)/', $var, $match);
if(count($match) > 0) {
$ticketID = $match[0];
}
preg_match('/Response ID = :([0-9]+)/', $var, $match);
if(count($match) > 0) {
$responseID = $match[0];
}
var_dump($ticketID, $responseID);
输出:
string 'Your Ticket ID = :68' (length=20)
string 'Response ID = :45' (length=17)