Jump to content

Recommended Posts

I have cURLed a page to my php page with the output being $output

 

I am now trying to get only parts of that page to display. I want to display what is inside <span class="XbcFRAR"> and </span> which is simply a number.

 

Here is my preg_match stuff that I have but all it displays is "Array"

 

preg_match_all('/<span class=\"XbcFRAR\">(.*?)< \/span>/', $output, $content);

echo $content;

 

 

I am asking for the correct regex to display the contents of the span tag with that class. I might even be using the wrong preg_ function for all I know at this point.

 

 

Contact me through AIM if you would like another way to help me out: MadLittleMods@gmail.com

 

Thanks for all replies and external links.

Link to comment
https://forums.phpfreaks.com/topic/223751-display-tag-contents/
Share on other sites

You've got a space in that regex that probably doesn't belong.

 

So far so good. $content is an array, so how about you try to figure out what's in it, and then access the bits that you want? Reading the manual is also a great idea.

You've got a space in that regex that probably doesn't belong.

 

So far so good. $content is an array, so how about you try to figure out what's in it, and then access the bits that you want? Reading the manual is also a great idea.

 

 

Now I am using this code which works in a regex tester but not on my page...

 

NOTE: (on the regex tester) Instead of $output i put the actual html from the cURL.

 

preg_match_all('/<span class(.*?)XbcFRAR(.*?)>(.*?)<\/span>/', $output, $content);

echo $content[3];

 

 

I think that the preg_ isnt searching the actual html code displayed from the cURL. Instead it is searching what it was defined in the code which was:

$output = curl_exec($ch);

 

How do i search what is being displayed on the page from teh cURL or whatever cURL is bringing in instead of what it is defined as in the code?

Do you know about the var_dump() function?  You might find it helpful to understand what you've got in your variables at various places.  I don't really understand your most recent question.  Curl acts like a client/browser and gets exactly what a browser would get --- the html code for the page requested.  I assumed from your original question you know what the data is that you want. 

I did use var_dump previously and now with that new regex it outputs a lot of stuff - basically the whole thing over twice.

 

But i do notice that almost what I want is all " quoted..

 

There is a few extra items but they have the same class etc so it makes sense...

 

It is still giving me a bunch of extra stuff though that i do not want to see..

Well.. since the modify button has disapeared i will just reply..

 

after doing this instead.

 

var_dump($content[3]);

 

I got the 3 span tags... So actually it is working and echo just doesnt show them...

 

This is the output:

array(3) { [0]=> string(58) "" [1]=> string(5) "15830" [2]=> string(3) "Pro" }

 

How can i make [1] which is 15830 into a variable?

 

This is just my guess $content[3]=>[1] = $number;

 

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.