element selector ?

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
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

element selector ?

Post by aneuryzma »

Hi,

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

getElementById('id');

thanks
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

Re: element selector ?

Post by waseem83 »

var abc=document.getElementById('idOfSpecificHtmlElement').value;

YOu write this code u will get value in abc variable of javascript.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: element selector ?

Post 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.
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: element selector ?

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: element selector ?

Post 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/).
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: element selector ?

Post 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
Last edited by Benjamin on Tue Jun 23, 2009 10:18 am, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply