Solved

Find String in an HTML

Posted on 2011-03-08
2
278 Views
Last Modified: 2012-05-11
Anybody knows how can i find the words in the string with another function for avoid regular expression use?
Thanks a lot.
0
Comment
Question by:amedio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:amedio
ID: 35070520
I attach the php code:

Hi, i´m trying to searh a couple of words in a String that has been gather from an HTML document file. This code doesn´t work, i think the problem is in the accent (character over the é), anyway i think is better to use some function or expression that searchs the exactly two words in the string, because probably the word "Datos" appears in other part of the HTML...
Thanks a lot for your help.

// the function file_get_html and $element->plaintext is gather from the "Simple HTML DOM" class
$url = "prov.html";
$data = file_get_html($url);
foreach($data->find('a') as $element)
{
// Regular expressions for clean spaces in the string
                  $pattern = '/^(?:\s| )+|(?:\s| )+$/';
                  $string = preg_replace($pattern, '', $element->plaintext);
                  $pattern = '/^( )+/';
                  $string = preg_replace($pattern, '', $string);
if ($string != 'Datos Técnicos')
{
echo 'NO' .  '<br>';
}
else
{
echo 'YES' . '<br>';
}
}
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35071048
Is there a reason why you cannot use strrpos?

e.g.
if (!strpos($element, 'Datos Técnicos'))
{
	echo 'NO' .  '<br>';
}
else
{
	echo 'YES' . '<br>';
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question