CSS Selector Engine for PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

CSS Selector Engine for PHP

Post 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
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: CSS Selector Engine for PHP

Post by The_Anomaly »

What do you mean by a CSS Selector? And what would you want PHP to do with it?
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

Re: CSS Selector Engine for PHP

Post 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.
Post Reply