F*U*R*B*Y*   -  Dec 07, 2014

I've been out of PHP too long, and can't get a simple preg_match to work for me. Perhaps I'm going at this the wrong way, can anyone give me some help? hahaha!!!


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);

preg_match('/<i>Total Bans: |\d|</i>/igm', $data, $matches);



I basically want it to return the amount of Total Bans. but its not outputting anything :(

Hawkee  -  Dec 07, 2014

You should backslash your greater than/less than signs and I usually surround my match with parenthesis.

sean  -  Dec 07, 2014

Yup, just need to escape your literal forward slash then you're golden. Also, as Hawkee suggested, it's more common to use parenthesis for matching. Consider the following:

preg_match('/<i>Total Bans: (\d)<\/i>/ims', $data, $matches);

PS: How you been?!

F*U*R*B*Y*  -  Dec 09, 2014

Thanks lads!

Can't believed I over-looked something so simple as that hahahaha!

Yeah not too bad sean, been a bit under the weather in regards to health (Living in hospital it feels like!) But I'm getting there!


Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.