ilikemath2002 Posted February 9, 2009 Share Posted February 9, 2009 Can I use cURL instead of file_get_contents? It would look something like this: <?php SOMECURLCODE $data = curl_exec($ch); $regex = '/Page 1 of (.+?) results/'; preg_match($regex,$data,$match); var_dump($match); echo $match[1]; ?> Also, how do I change this source to be used as $regex: <span class="billing funorb"> <span class="credits"><b>(.+?)</b><br />Days</span> Quote Link to comment https://forums.phpfreaks.com/topic/144470-text-parsing/ Share on other sites More sharing options...
.josh Posted February 9, 2009 Share Posted February 9, 2009 Can I use cURL instead of file_get_contents? It would look something like this: Yes you can use curl, but it is meant for real interaction between two servers. Like, if you want to send data to a server's form and get the data generated from the response. That sort of thing. If you're just scraping the page, curl is making it more complicated than it needs to be. Stick with file_get_contents. Also, how do I change this source to be used as $regex: <span class="billing funorb"> <span class="credits"><b>(.+?)</b><br />Days</span> Don't quite understand what you mean...are you saying you want to grab the stuff between the bold tags? // may or may not need the 's' modifier, depending on if boundaries will be on multiple lines or not $regex = '~<span class="credits"><b>(.+?)</b>~s'; preg_match($regex,$data,$match); Quote Link to comment https://forums.phpfreaks.com/topic/144470-text-parsing/#findComment-758261 Share on other sites More sharing options...
ilikemath2002 Posted February 9, 2009 Author Share Posted February 9, 2009 Thanks CV, that's what I needed, I thought it would need \ or something before the tags. Quote Link to comment https://forums.phpfreaks.com/topic/144470-text-parsing/#findComment-758457 Share on other sites More sharing options...
.josh Posted February 9, 2009 Share Posted February 9, 2009 Thanks CV, that's what I needed, I thought it would need \ or something before the tags. Just depends on what delimiter you are using for the pattern. For instance, if I chose / as my pattern delimiter, I would have to escape any /'s in the pattern, like this: "/<span class="credits"><b>(.+?)<\/b>/s" so the regex engine knows that that / for the closing b tag isn't the end of the pattern. Quote Link to comment https://forums.phpfreaks.com/topic/144470-text-parsing/#findComment-758505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.