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
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
)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.