Jump to content

Parse css with PHP?


ishboo

Recommended Posts

I'm trying to write this php application that retrieves information from another website that does not have a developer API or anyhting of the sort, they gave me permission to make my own stuff so I won't be angering them by overloading the server, thought to clear that up before anyone said anyhting. I am trying to get a string of information that is alway on a page in a <span id="co">string I want</span>. What would be the best way to do this? If there is no function designed for this(I'm pretty sure there isn't) then maybe I could get the source of the page and then just find the span tags I want with a simple function there. If I did that, how should I get the source of the web page? I'm am also open to any other suggestions and thanks in advance.

Link to comment
Share on other sites

I would suggest regular expressions, but if it's just plain span tags then explode would be fine, or if you don't feel like messing with regular expressions, then explode would be fine too.

 

A regular expression example with $content being the target pages content:

 


$pattern = "/<span(.*?)>(.*?)</span>/";

if(preg_match($pattern, $content, $matches)) {
echo $matches[1]; //the stuff in the span tags
}

 

Note: I'm not a regexp expert, infact I often forget syntaxes and modifiers, so that may or may not work haha.

Link to comment
Share on other sites

I saw this on ajaxian. It could be interesting to try. It's called phpQuery which is a php port of jQuery. It looks like you should be able to select elements by css selectors and return them as a php object. Here's the link to the project: http://wiadomosc.info/plainTemplate/

 

If anyone tries this out, let me know what you think.

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.