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
CSS Selector Engine for PHP
Moderator: General Moderators
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: CSS Selector Engine for PHP
What do you mean by a CSS Selector? And what would you want PHP to do with it?
Re: CSS Selector Engine for PHP
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:
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:
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.
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*/
}
Code: Select all
$(".MainContent h2").DoSomething(
{
/*manipulation code goes here*/
});
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.