From: Ashley Sheridan on
On Sat, 2010-04-03 at 20:51 +0530, vikash.iitb(a)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 Steinger <piero(a)the-admins.ch> wrote:
>
> > 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 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.
> > >
> > > Now, I can extract each question by using javascript --
> > >
> > > document.getElementById("question").innerHTML;
> > >
> > > -- and stepping through each page, but I don't want to use javascript
> > > for this.
> > >
> > > I have not found/created a working example of this using PHP. I tried
> > > using PHP's getElementByID(), but that requires the target file to be
> > > valid xml and the string to be contained within an ID and not a class.
> > > These pages do not support either requirement.
> > >
> > > Additionally, I realize that I can load the files and parse out what
> > > is between the <p> tags, but I was hoping for a "GetElementByClass"
> > > way to do this.
> > >
> > > So, is there one?
> > >
> > > Thanks,
> > >
> > > tedd
> >
> > 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
> >
> >

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


From: Piero Steinger on
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 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.
>>>
>>> Now, I can extract each question by using javascript --
>>>
>>> document.getElementById("question").innerHTML;
>>>
>>> -- and stepping through each page, but I don't want to use javascript
>>> for this.
>>>
>>> I have not found/created a working example of this using PHP. I tried
>>> using PHP's getElementByID(), but that requires the target file to be
>>> valid xml and the string to be contained within an ID and not a class.
>>> These pages do not support either requirement.
>>>
>>> Additionally, I realize that I can load the files and parse out what is
>>> between the <p> tags, but I was hoping for a "GetElementByClass" way to
>>> do this.
>>>
>>> So, is there one?
>>>
>>> Thanks,
>>>
>>> tedd
>>>
>> 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:
>> /\<p\s*class\=\"question\"\s*\>(.*)\<\/p\>
>>
>>
>> (my first contribute here, I beg your pardon if something went wrong)
>>
>> Regards,
>>
>> Valentin Dreismann
>>
>>
>
> The . won't match new line characters, so you'll have to add those in
> too.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>

It matches new lines with the modifier s.
http://ch2.php.net/manual/en/reference.pcre.pattern.modifiers.php

Greetz
Piero

From: "Peter Pei" on

>
> 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
give me the feeling that this is a one time thing, and he just wanted to
extract the questions.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: "Peter Pei" on
On Sat, 03 Apr 2010 09:21:17 -0600, Ashley Sheridan
<ash(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 the same kind of page but
with sort of 3D looking.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
From: tedd on
At 8:11 AM -0600 4/3/10, Peter Pei wrote:
>On Sat, 03 Apr 2010 08:58:44 -0600, Ashley Sheridan
><ash(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;
>>>
>>
>
>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

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com