Maybe have a look at phpQuery: http://code.google.com/p/phpquery/?
I haven't used it myself so I'm not 100% sure it does what you want, but since it is a server-side implementation of jQuery to select from the DOM, using CSS selectors, I think it could be useful in your case.