scs Posted July 2, 2008 Share Posted July 2, 2008 Hi all I'm having some trouble parsing a URL from downloaded site content using fsockopen. I'm making a Voting system for my site and this will be part of it. I am simply just getting a URL. The URL is very unique yet I can't seem to get it. The end of the URL has a session tag so its always changing. There's also a class in the URL tag that's not on any other link. That should definitely help! I thought. lol So here is what I got so far After downloading the site into a variable I'm trying to parse all info I want from it. $regex = '/href="(.*?)" class="buttongo"/'; preg_match($regex, $output_data, $stuff); print_r($stuff); //Nothing comes out The URL looks like this <a href="http://www.mysite.com/index.php?a=in&u=username&sid=rjhgf2hWm9WDFTkgx9JJd290udtkIgfM" class="buttongo">Enter</a> I want the URL as a whole so I was just trying to match the unique class. And I know the data is correct because I got the URL from echo 'ing the data im parsing. Also as you can see in my code I didn't include any of the tag. Like, <a> cause im not sure what I need to escape and if thats part of my problem. I've never been able to find html tags very well. So any tips on that would be great as well! I hope thats enough info to understand what I am doing. Thanks Zach Quote Link to comment https://forums.phpfreaks.com/topic/112861-help-parsing-a-url/ Share on other sites More sharing options...
mbeals Posted July 2, 2008 Share Posted July 2, 2008 insert echo $output_data; before the preg_match and post the contents. I just tested: $string = '<a href="http://www.mysite.com/index.php?a=in&u=username&sid=rjhgf2hWm9WDFTkgx9JJd290udtkIgfM" class="buttongo">Enter</a>'; $regex = '/href="(.*?)" class="buttongo"/'; preg_match($regex, $string, $stuff); print_r($stuff); //Nothing comes out and it spit out: Array ( [0] => href="http://www.mysite.com/index.php?a=in&u=username&sid=rjhgf2hWm9WDFTkgx9JJd290udtkIgfM" class="buttongo" [1] => http://www.mysite.com/index.php?a=in&u=username&sid=rjhgf2hWm9WDFTkgx9JJd290udtkIgfM ) so make sure that your $output_data variable is defined and it contains what you think it does just before being parsed by the regex Quote Link to comment https://forums.phpfreaks.com/topic/112861-help-parsing-a-url/#findComment-579956 Share on other sites More sharing options...
scs Posted July 2, 2008 Author Share Posted July 2, 2008 wow It worked! Thanks so much!! Zach Quote Link to comment https://forums.phpfreaks.com/topic/112861-help-parsing-a-url/#findComment-580114 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.