Jump to content

[SOLVED] simple string parsing


marklarah

Recommended Posts

So I have the HTML for a remote webpage stored in a variable (gotten through cURL). It's htmlentities'd, so I have the text for it. I need to get a specific link from this webpage. I think there are other links, but there is one in a specific format.

 

The format is

<a href="http://linkhere" style="font-size:15px;">

I have read the things online how to parse it, but I can't seem to find a specific one which will do this.  How would I go about doing it?

 

Thanks...Mark.

Link to comment
Share on other sites

Then give me the exact string you are trying to get out, or modify it to fit your needs. The above should give you a good idea how to modify it.

 

If it is not echoing anything, it is not finding any matches. Simple as that.

Link to comment
Share on other sites

Ok, sort of half-fixed it. Turns out the entities does matter, i'm using

preg_match('~<a href="(.+?)" style="font-size:15px;">~si', $result, $matches);

 

Now, I get a lot of stuff, but the last thing is the link. the first the characters of what's on the page is

?">
- I presume this is the preg_match. If this needs editing then, then what comes before the link is
id="link">
- there is a space between the end of that div and the link/
Link to comment
Share on other sites

but I'm still getting lots of stuff before the link.

 

Hmm, that gives me a ton of information. Post your current code, and the "stuff" before the link.

 

Given that you take the original code I posted above it works fine right? So the issue lies with how the data is stored in the string. Do a print_r on the $matches variable, view the source and paste that array here as well.

 

Just to make sure you are echoing $matches[1] and not $matches[0].

Link to comment
Share on other sites

print_r returns exactly the same. The problem is, there are a few links on the page, so it goes from the first link with <a href="..... to our link we're trying to single out, because it is unique, with the style.

 

Can we edit the preg_match to identify a line of text before the link?

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.