Jump to content

preg_match from a whole html page.


netpumber

Recommended Posts

Hello..

 

Lets say we have this source code returned through cURL into a string called $result .

<font face="Arial" size=2>
<p>Member Name</font> <font face="Arial" size=2>no2</font>
<p>
<font face="Arial" size=2>My name is 'Kate' and im fine.</font>
<p>
<font face="Arial" size=2>/member.php</font><font face="Arial" size=2> today</font> 

 

i wont to find and print the string 'Kate'.

So i wrote this script

 

$pattern = "/My name is '(.*)' and im fine/i";

preg_match($pattern , $result, $matches);

print_r($matches);

 

but the array matches is still empty and this is what it prints :

 

Array ( )

 

Whats going wrong ? How can i fix it ?

 

Thanks for your time.

Link to comment
https://forums.phpfreaks.com/topic/248491-preg_match-from-a-whole-html-page/
Share on other sites

$result = <<<EOD
<font face="Arial" size=2>
<p>Member Name</font> <font face="Arial" size=2>no2</font>
<p>
<font face="Arial" size=2>My name is 'Kate' and im fine.</font>
<p>
<font face="Arial" size=2>/member.php</font><font face="Arial" size=2> today</font>
EOD;

$pattern = "/My name is '([^']*)'/i";
preg_match($pattern , $result, $matches);
print_r($matches);

 

Output:

Array
(
    [0] => My name is 'Kate'
    [1] => Kate
)

yes... you are right.. but i forgot to say that in the cURL setup i use and proxy (tor) and if i have these lines uncomment doesn't work.

 

curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); 
curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:9050');

 

and when i comment them all works fine..

 

Who knows..?  :-\

 

edit: i restart tor service and now all works..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.