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
https://forums.phpfreaks.com/topic/149887-solved-simple-string-parsing/
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/

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].

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.