Page 1 of 1

element selector ?

Posted: Tue Jun 23, 2009 5:56 am
by aneuryzma
Hi,

how can I select an element of my html document using php ?

getElementById('id');

thanks

Re: element selector ?

Posted: Tue Jun 23, 2009 6:00 am
by waseem83
var abc=document.getElementById('idOfSpecificHtmlElement').value;

YOu write this code u will get value in abc variable of javascript.

Re: element selector ?

Posted: Tue Jun 23, 2009 6:06 am
by jayshields
Using PHP you can't just get a HTML element, the HTML is usually produced by PHP, so you should have access to whatever you want already. On the other hand, you could do file_get_contents() on a HTML file and then parse it with an XML parser or similar, and work from there.

Re: element selector ?

Posted: Tue Jun 23, 2009 6:21 am
by aneuryzma
uhm ok... than I can only use client-side technologies to edit existent html ?

My problem is that I want to automatically change the html code inserted by my customer in content management system editor

Re: element selector ?

Posted: Tue Jun 23, 2009 6:27 am
by onion2k
You can use DOMDocument if it's compiled into your version of PHP, or SimpleHTMLDOM if it's not (http://sourceforge.net/projects/simplehtmldom/).

Re: element selector ?

Posted: Tue Jun 23, 2009 6:40 am
by aneuryzma
If I use DOMDocument, should I load the html like this ?

Code: Select all

$xmlDoc = new DOMDocument(); 
$xmlDoc->load( 'myPage.html' );
or is any other easier way to do it ?

thanks