×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

html parser simple dom

html parser simple dom

html parser simple dom

(OP)
Does anyone know anything about simple dom parser? I'm look at a problem with the find function
foreach($html->find('span itemprop="name"') as $cat)
	echo $cat->src; 

even though there is only one instance I get more after it>? how do I get first instance

RE: html parser simple dom

Not sure what you are attempting to return with itemprop="name".

If you want to specify a span with a property named "itemprop" that has a value of "name", you can do something like:

foreach($html->find('span[itemprop=name]') as $cat)

if you are looking for a span that has a property named "name" with any value, then:

foreach($html->find('span[name]') as $cat)


beyond that, spans don't have src attributes so doing $cat->src will return nothing. Using the "plaintext" option instead will return the text inside the span.

CODE

foreach($html->find('span[name]') as $cat)
echo $cat->plaintext; 

This might also help:
http://nimishprabhu.com/top-10-best-usage-examples...

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: html parser simple dom

(OP)
thanks will try it, the text i want is inside

CODE

<span itemprop="name"> 

... can i also ask, why does'nt simple dom let you put stuff into an array?

CODE

foreach($html->find('img')as $img)
   $items[]=$img->src;

print_r ($items); 

RE: html parser simple dom

(OP)
this one worked for reference to this thread,

CODE

foreach($html->find('span[itemprop=name]') as $cat) 

I cant understand why I have to dismantle the html page source into something different

RE: html parser simple dom

(OP)
I'm getting there BUT... if I have a number of th elements condition as a title is one of them, what is the find() on that please? inside the html elements is this src or name?

4-Condition:

RE: html parser simple dom

You mean your html is something like: <th title="somethinghere">?

If so just use the same general structure:

CODE

$html->find(th[title]); 

This looks for th tags that have a title attribute or property.

Only image tags and iframes have a "src" attribute. ( <img src="path/to/img">, <iframe src="path/to/file.html"> ) So only if you are trying to get the image's or iframes path would you use "src". If you are trying to get the contents of any other HTML element, use "plaintext".

Quote:


... can i also ask, why does'nt simple dom let you put stuff into an array?

It does.

For non image elements this works for me:
$myarray[] = $element->plaintext;

Quote:


I cant understand why I have to dismantle the html page source into something different

Not sure what you mean. If you are looking for a specific element then you need to tell the find() function what it is. You are not dismantling anything, you are specifying what you are looking for in a way that makes sense to the dom parser.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: html parser simple dom

(OP)
Ive got my head round it now

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close