Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching a html page for a font using PHP 1

Status
Not open for further replies.

chineerat

Technical User
Oct 12, 2003
42
TT
hello there
i would like to search a query generated page for a particular font colour/type for example:
the link:


what is the PHP function for extracting font of the colour green? or fonts: blue and underline.

The difficulty is that google uses classes. I just used google as an example. The site i am expected to use may not have classes embeded. I am expecting the site to use simple basic HTML.
for example:
"<html><body><font color="green">.........<font color="green"> </body> </html>
am i to use a String search?

can anyone help, THANKS alot in advance.
 
use preg_match_all()

the regex and function call would look something like this (this is an imperfect regex but it should give you a start).

Code:
$html = "<html><body><font color="green">first text to be captured</font>some other text that will not be captured<font color="green">text to be captured</body> </html>"
$pattern = '/<font color="green">(.*?)</font>/i';
preg_match_all($pattern, $html, $matches);

echo "<pre>".print_r($matches, true);
 
i am getting the error
Parse error: parse error, unexpected T_VARIABLE in c:\inetpub\ on line 1

does it have to do with the fact that
$html uses double quotes and <font colour "green"> has double quotes?
will this cause a conflict?
 
probably more to do with a lack of semicolon at the end of line 1.

but also, the enquoting was wrong, as you point out.

try this
Code:
$html = <<<HTML
<html><body><font color="green">first text to be captured</font>some other text that will not be captured<font color="green">text to be captured</body> </html>
HTML;

or put the html in a separate file and
Code:
$html = file_get_contents ("separatefile.txt");
 
i didn't get method one to work, but method 2 works.
thanks
 
the heredoc syntax is very sensitive to spaces on the first and last lines

Code:
echo <<<HTML[red]NO MORE SPACES HERE[/RED]
...
...
...
HTML;[red]the ending delimeter (HTML) must be hard against the left edge and there must be no characters after the delimiter apart from the semicolon[/red]

glad you got it sorted though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top