2017-09-08 3 views
-3

str_replace et preg_match ne fonctionnent pas dans le code suivant.php- preg_match ne fonctionne pas ni str_replace

$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'; 
} 
+0

Bien sûr, ils ne peuvent pas trouver la chaîne dans le texte de la page. Le texte est là mais il contient des nouvelles lignes qui ne sont pas présentes dans votre chaîne. – axiac

Répondre

0

Vous ne pouvez pas insérer de nouvelle ligne et d'espace dans le code html. Regardez

   <td colspan="3"> 
        Corp off: I – 128, 2nd Floor, Mohammadpur, Bikaji, New Delhi 110066. 
<br> 
© Copyright 2014 by Ima Appweb. All Rights Reserved. 
         </td> 

Chaque saut de ligne ont des symboles de nouvelle ligne. Il y a beaucoup d'espaces avant <td>