我在做
preg_match("/\<\/p\> (\d*?) /", $error, $matches)
在哪里$error="bla-bla-bla </p> 12345 bla-bla-bla"
奇怪的是它没有找到匹配项,即使我仔细检查了正则表达式。
为什么它不起作用?
这是完整的代码:
$values=$form->getValue();
$url = "http://something.freshdesk.com/helpdesk/tickets.xml";
$request = "<helpdesk_ticket><description>".$values['subject']."</description><email>".$username."</email></helpdesk_ticket>";
echo $request;
$headers = array('Content-Type: application/xml','Content-Length: ' . strlen($request));
var_dump($headers);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, 'email@email.com:password');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
// curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$http_result = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
if ($error) {
print "<br /><br />$error";
} else {
if (preg_match("/\<\/p\> (\d*?) /", $error, $matches)) {
$ticket_id = $matches[1];
print "Ticket submitted: $ticket_id\n";
}
print "<br /><br />Location header not found";
var_dump($matches);
var_dump($http_result);
echo $error;
echo $http_result;