Jump to content

Help parsing a URL


scs

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
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.