Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/144470-text-parsing/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/144470-text-parsing/#findComment-758261
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/144470-text-parsing/#findComment-758505
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.