Jump to content

Recommended Posts

Hello, I'm currently working on using regex to scrape a few lines of code and display it:

 

$scrape = file_get_the_contents($url) ; 
$regex = '/<td class="info">    <a href="(.+?)" title=/';
preg_match($regex,$scrape,$results);
var_dump($results);
echo $results;

 

and this is the result I get : array(2) { [0]=>  string(61) "

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/
Share on other sites

Hello, I'm currently working on using regex to scrape a few lines of code and display it:

 

$scrape = file_get_the_contents($url) ; 
$regex = '/<td class="info">    <a href="(.+?)" title=/';
preg_match($regex,$scrape,$results);
var_dump($results);
echo $results;

 

and this is the result I get : array(2) { [0]=>  string(61) "

 

 

so...what's the problem?

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696011
Share on other sites

a) How are we to know which URL you are scraping? (file_get_the_contents($url) doesn't tell us what the source code is)

b) In your pattern '/<td class="info">    <a href="(.+?)" title=/', I hope you realise that those spaces between the td tag and the a tag are actually needed to be matched (if you do not desire those spaces, remove them from the pattern).

c) an answer like 'and this is the result I get : array(2) { =>  string(61) " ' doesn't tell us squat.

 

My advice would be to provide a sample of the URL code you are trying to scrape, as your post tells us nothing (other than the involement of a td tag and an a tag (with some spaces in between for some odd reason).

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696646
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.