Solved

Find String in an HTML

Posted on 2011-03-08
2
275 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
REGEX HELP 11 43
PHP AJAX Wordpress 9 21
send post values 7 26
PHP insert data in to database... this is not letting me in insert data...please help! 7 38
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 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