-2

我有这样的字符串:我的代码是:

$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 =:68and Response id =:45

当我打印块引用时,我得到了上面的文本。现在我想获取我的票证 ID 和响应 ID,但不知道如何?

4

1 回答 1

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)
于 2013-09-03T09:47:16.820 回答