netpumber Posted October 5, 2011 Share Posted October 5, 2011 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 More sharing options...
Psycho Posted October 5, 2011 Share Posted October 5, 2011 Work's fine for me when I copied that text into a variable called $result. However, that expression could be simplified to $pattern = "/My name is '([^']*)'/i"; Link to comment https://forums.phpfreaks.com/topic/248491-preg_match-from-a-whole-html-page/#findComment-1276104 Share on other sites More sharing options...
Psycho Posted October 5, 2011 Share Posted October 5, 2011 $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 https://forums.phpfreaks.com/topic/248491-preg_match-from-a-whole-html-page/#findComment-1276110 Share on other sites More sharing options...
netpumber Posted October 5, 2011 Author Share Posted October 5, 2011 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 https://forums.phpfreaks.com/topic/248491-preg_match-from-a-whole-html-page/#findComment-1276120 Share on other sites More sharing options...
xyph Posted October 5, 2011 Share Posted October 5, 2011 Masking your cURL requests? Seems legit. Link to comment https://forums.phpfreaks.com/topic/248491-preg_match-from-a-whole-html-page/#findComment-1276209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.