【发布时间】:2023-04-09 08:45:01
【问题描述】:
str_replace 和 preg_match 在以下代码中不起作用。
$url = 'http://www.ima-appweb.com/hub/emailers/2017-07/website-emailer-2/';
$opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
//Basically adding headers to the request
$context = stream_context_create($opts);
$html = file_get_contents($url,false,$context,0,2700);
$html = htmlspecialchars($html);
echo $html;
if(preg_match_all('#<td colspan="3"> Corp off: I – 128, 2nd Floor, Mohammadpur, Bikaji, New Delhi 110066. <br> © Copyright 2014 by Ima Appweb. All Rights Reserved. </td>#', $html)){
$outputs = str_replace('<td colspan="3"> Corp off: I – 128, 2nd Floor, Mohammadpur, Bikaji, New Delhi 110066. <br> © Copyright 2014 by Ima Appweb. All Rights Reserved. </td>','<td colspan="3"><strong> Address: '.$address.', '.$city.', '.$country.'<br/>'.$website.'<br/>© Copyright By sunny '.$company.'</strong></td>',$html);
} else {
echo 'didnot match';
}
【问题讨论】:
-
当然他们在页面的文本中找不到字符串。文本在那里,但它包含一些字符串中不存在的换行符。
标签: php regex str-replace