Page 1 of 1

CSS Selector Engine for PHP

Posted: Wed Dec 24, 2008 11:40 am
by Walid
Hi there,

Is there such a thing as a CSS selector engine for PHP?

I'm very used to jquery and its selector engine makes dom traversal/manipulation so easy. Is there something like it in PHP that could save my time, energy and hair?

Thanks

Re: CSS Selector Engine for PHP

Posted: Wed Dec 24, 2008 1:15 pm
by The_Anomaly
What do you mean by a CSS Selector? And what would you want PHP to do with it?

Re: CSS Selector Engine for PHP

Posted: Wed Dec 24, 2008 9:36 pm
by Walid
In CSS, selectors are used to select elements on an HTML page so that they can be styled. At a basic level, they are html elements (e.g. h1, h2 etc.) but can also include things like class names, id's, relationships etc.

In CSS, if we wanted to style all h2's which are children of of <div class="MainContent">, we would do:

Code: Select all

 
.MainContent h2
{
/*styling goes here*/
}
 
jQuery takes advantage of this to simply DOM traversal so that, if you wanted to do something to the same HTML elements (e.g. string replacement), you would do:

Code: Select all

 
$(".MainContent h2").DoSomething(
{
/*manipulation code goes here*/
});
 
Now to PHP, the HTML document has been put into a buffer ($HtmlBuffer). I now want to identify which parts of the HTML tree meet certain requirements (defined by a CSS Selector) and manipulate those parts.

So, in words, "grab the text contained within all h2's that are children of .MainContent and run a string replacement function on them".

I hope that makes things clearer and I hope there's a solution.