Convert HTML to text , for NEWS Abstract !

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
iranPHPmaster
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 6:13 pm
Location: Iran
Contact:

Convert HTML to text , for NEWS Abstract !

Post by iranPHPmaster »

hello

i have a news system ,i want show news abstract in home page with an image thumbnail.
i need to Convert HTML to text , and get all image tag for creating thumbnail.

but i dont know how can i catch all image tag SRC value ! :?:

please help me
thx :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The following is a response I gave to Heavy, which has code tucked away inside it to do what you want, and much more.
viewtopic.php?t=29312
iranPHPmaster
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 6:13 pm
Location: Iran
Contact:

i see that post , but i dont understand how can i use that !

Post by iranPHPmaster »

hi
thx for reply !
but i dont understand how i must use that code for this abstract !!!
can you say to me easyer !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I can't make it much simpler without doing it for you. I'm not going to do the work for you. The regex needed is inside the code I posted for Heavy. Find it, play with it.
iranPHPmaster
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 6:13 pm
Location: Iran
Contact:

in easy sample !

Post by iranPHPmaster »

if i want Export name of Image From Tag same this :

Code: Select all

<img class="a" src="a.jpg" width="10">
i must use ????
i use this :

Code: Select all

<img(.*)src="(.*)">
and i get export this :

Code: Select all

a.jpg" width="10
its not work , help :D ?!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ready the stickies. Search for greedy/ungreedy.
iranPHPmaster
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 6:13 pm
Location: Iran
Contact:

Post by iranPHPmaster »

thx Feyd !
whats your idea about this code ?

Code: Select all

<?php 
$input=implode('',file('http://www.yahoo.com')); 
$count_found=preg_match_all("#<img.*src=[\"\'](.*)(.gif|.jpg|.jpeg|.png|.bmp)[\"\'].*>#i", $input, $matches); 

print "$count_found Item Found<br><br>";

for($i=0;$i<=$count_found-1;$i++) {
	print "- Item[$i] = {$matches[1][$i]}{$matches[2][$i]}<br>";
}
//print_r($matches);
?>
i think its good , but not completed ?!
i must abstract an html with style !!!?

sample :
we have and heavy html file , i want catch some line of it with Style !!!

who its possible ?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

.* is greedy... it will mess your regex up. Use .*?
Post Reply