MadLittleMods Posted January 8, 2011 Share Posted January 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/ Share on other sites More sharing options...
requinix Posted January 8, 2011 Share Posted January 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156573 Share on other sites More sharing options...
gizmola Posted January 8, 2011 Share Posted January 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156586 Share on other sites More sharing options...
MadLittleMods Posted January 8, 2011 Author Share Posted January 8, 2011 var dump gives: array(2) { [0]=> array(0) { } [1]=> array(0) { } } I have read lots of the preg match function manuals (preg_match, preg_match_all, preg_match_replace) Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156807 Share on other sites More sharing options...
MadLittleMods Posted January 8, 2011 Author Share Posted January 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156854 Share on other sites More sharing options...
gizmola Posted January 9, 2011 Share Posted January 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156890 Share on other sites More sharing options...
MadLittleMods Posted January 9, 2011 Author Share Posted January 9, 2011 I am thinking that $output does not equal what cURL is outputting and instead preg_match_all is searching this: $output = curl_exec($ch); Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156893 Share on other sites More sharing options...
gizmola Posted January 9, 2011 Share Posted January 9, 2011 Where is your code? Also, instead of "thinking" use var_dump() and then you'll know what is in $output, as i previously suggested. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156899 Share on other sites More sharing options...
MadLittleMods Posted January 9, 2011 Author Share Posted January 9, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156902 Share on other sites More sharing options...
MadLittleMods Posted January 9, 2011 Author Share Posted January 9, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156907 Share on other sites More sharing options...
MadLittleMods Posted January 9, 2011 Author Share Posted January 9, 2011 SOLVED! Use this code... preg_match_all('/<span class(.*?)XbcFRAR(.*?)>([0-9]{1,})<\/span>/', $output, $content); foreach ($content[3] as $key => $final) { echo "$final"; } Thanks for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/223751-display-tag-contents/#findComment-1156940 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.