[PHP] GetElementByClass?

2010-04-03 Thread tedd
Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I extract the string Who is Roger Rabbit? from each page using php? You

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I extract the

Re: [PHP] GetElementByClass?

2010-04-03 Thread vikash . iitb
I use this: http://simplehtmldom.sourceforge.net/ Check it out. Thanks, Vikash Kumar -- http://vika.sh On Sat, Apr 3, 2010 at 8:28 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages

Re: [PHP] GetElementByClass?

2010-04-03 Thread Adam Richardson
p class=question Who is Roger Rabbit? /p My question is -- how can I extract the string Who is Roger Rabbit? from each page using php? You see, I want to store the questions in a database without having to re-type, or cut/paste, each one. I have not found/created a working example of

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
On Sat, 03 Apr 2010 08:58:44 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 08:11 -0600, Peter Pei wrote: On Sat, 03 Apr 2010 08:58:44 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
No javascript's getElementByID() won't work here. As question is a class, not an ID. But like what was mentioned here, you can use getElementByClass() with Opera, and that will work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] GetElementByClass?

2010-04-03 Thread dispy
Am 03.04.2010 16:29, schrieb tedd: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I extract the string Who is

Re: [PHP] GetElementByClass?

2010-04-03 Thread Piero Steinger
On 03.04.2010 16:29, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I extract the string Who is Roger

Re: [PHP] GetElementByClass?

2010-04-03 Thread vikash . iitb
If you are open to use javascript then a js library like jQuery may help in selecting all elements from a particular class. $(.clasName) Thanks, Vikash Kumar -- http://vika.sh On Sat, Apr 3, 2010 at 8:46 PM, Piero Steinger pi...@the-admins.ch wrote: On 03.04.2010 16:29, tedd wrote: Hi

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
Yes, because Opera is pretty much leading the way with its HTML5 support. Not even Firefox supports as much as Opera does. Thanks, Ash http://www.ashleysheridan.co.uk Opera 10.10 is a very nice version, but 10.50 could be quite slow with some web pages. I still remember that once

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 17:03 +0200, dispy wrote: Am 03.04.2010 16:29, schrieb tedd: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
Why don't you just use REGEX? I don't know any possibility to easily process contents which are not valid XML/XHTML just because there's no library to load such stuff (but put me in right there). I'm not an expert of REGEX, but I think the following would do it:

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
Hi You could replace the class with id and then go on with JavaScript. A possible better way are regular expressions... Greetz Piero -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yes, and jquery is hosted on Microsoft CDN, don't

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 08:22 -0600, Peter Pei wrote: Yes, because Opera is pretty much leading the way with its HTML5 support. Not even Firefox supports as much as Opera does. Thanks, Ash http://www.ashleysheridan.co.uk Opera 10.10 is a very nice version, but 10.50 could

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 20:51 +0530, vikash.i...@gmail.com wrote: If you are open to use javascript then a js library like jQuery may help in selecting all elements from a particular class. $(.clasName) Thanks, Vikash Kumar -- http://vika.sh On Sat, Apr 3, 2010 at 8:46 PM, Piero

Re: [PHP] GetElementByClass?

2010-04-03 Thread Piero Steinger
On 03.04.2010 17:17, Ashley Sheridan wrote: On Sat, 2010-04-03 at 17:03 +0200, dispy wrote: Am 03.04.2010 16:29, schrieb tedd: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
I think Tedds main reason not to use Javascript is that he needs it to be done on the server rather than the client machine. ps. please use bottom posting on the list. Thanks, Ash http://www.ashleysheridan.co.uk But he also mentioned that he wanted to avoid copy and paste... it does

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
On Sat, 03 Apr 2010 09:21:17 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: s, first browser to have tabs, first to have that odd homepage with thumbnails of y Talking about Opera's 'speed dial... I downloaded safari yesterday (which I didn't like last time I used it), it now has

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 8:11 AM -0600 4/3/10, Peter Pei wrote: On Sat, 03 Apr 2010 08:58:44 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: -snip- Now, I can extract each question by using javascript -- document.getElementById(question).innerHTML;

Re: [PHP] GetElementByClass?

2010-04-03 Thread Nathan Nobbe
On Sat, Apr 3, 2010 at 8:29 AM, tedd t...@sperling.com wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 3:58 PM +0100 4/3/10, Ashley Sheridan wrote: I don't think there is a getElementsByClass function. HTML5 is proposing one, but that will most likely be implemented in Javascript before PHP Dom. There is a way to tidy up the HTML to make it XHTML, but I'm not sure what it is. If you know

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
Somejavascript engine already support GetElementByClass, for example Opera does. My example shows how, namely: document.getElementById(question).innerHTML; will return the value within the class. Cheers, tedd In your original post, you said the data you had was: p class=question

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 8:14 AM -0600 4/3/10, Peter Pei wrote: No javascript's getElementByID() won't work here. As question is a class, not an ID. But like what was mentioned here, you can use getElementByClass() with Opera, and that will work. Sort of. Like I said, the folling will work:

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 5:16 PM +0200 4/3/10, Piero Steinger wrote: Hi You could replace the class with id and then go on with JavaScript. A possible better way are regular expressions... Greetz Piero I can go with javascript as-is (what I showed) and don't have to change any html. Cheers, tedd -- ---

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 4:22 PM +0100 4/3/10, Ashley Sheridan wrote: I think Tedds main reason not to use Javascript is that he needs it to be done on the server rather than the client machine. ps. please use bottom posting on the list. Thanks, Ash Yeah, one reason was to get this done in one operation and

Re: [PHP] GetElementByClass?

2010-04-03 Thread Nathan Nobbe
On Sat, Apr 3, 2010 at 10:18 AM, tedd t...@sperling.com wrote: At 8:14 AM -0600 4/3/10, Peter Pei wrote: No javascript's getElementByID() won't work here. As question is a class, not an ID. But like what was mentioned here, you can use getElementByClass() with Opera, and that will work.

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 9:14 AM -0600 4/3/10, Peter Pei wrote: Somejavascript engine already support GetElementByClass, for example Opera does. My example shows how, namely: document.getElementById(question).innerHTML; will return the value within the class. Cheers, tedd In your original post, you said the

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 12:18 PM -0400 4/3/10, tedd wrote: At 8:14 AM -0600 4/3/10, Peter Pei wrote: No javascript's getElementByID() won't work here. As question is a class, not an ID. But like what was mentioned here, you can use getElementByClass() with Opera, and that will work. Sort of. Like I said, the

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
Sort of. Like I said, the folling will work: document.getElementById(question).innerHTML; While you are using a getElementById, which returns an ID, but adding .innerHTML will return the class value. Try it. Cheers, tedd No, this will not work, if it appeared working, please re-check

Re: [PHP] GetElementByClass?

2010-04-03 Thread tedd
At 10:03 AM -0600 4/3/10, Nathan Nobbe wrote: -snip- code Your code worked like a charm. Thanks. Now, I can extract each question by using javascript -- document.getElementById(question).innerHTML; tedd, are you slipping? i thought you were searching by the class attribute, lol.

Re: [PHP] GetElementByClass?

2010-04-03 Thread Ashley Sheridan
On Sat, 2010-04-03 at 09:33 -0600, Peter Pei wrote: Sort of. Like I said, the folling will work: document.getElementById(question).innerHTML; While you are using a getElementById, which returns an ID, but adding .innerHTML will return the class value. Try it. Cheers,

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
It might have worked in Internet Explorer, as for a while that browser got confused over the class and id if two different elements on a page had the same class and id values. Thanks, Ash http://www.ashleysheridan.co.uk IE and Opera were the two I tested with. -- Using Opera's

Re: [PHP] GetElementByClass?

2010-04-03 Thread Peter Pei
?php // here is where you load a single file or change to iterate over a // directory of files $oDomDoc = DOMDocument::loadHTMLFile('./tedd.html'); // here is where you search for the question sections of each file $oDomXpath = new DOMXPath($oDomDoc); $oNodeList =