PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
eshban
Forum Contributor
Posts: 184 Joined: Mon Sep 05, 2005 1:38 am
Post
by eshban » Tue Dec 19, 2006 11:02 pm
Hello,
I have read a file from PHP function.
I want to save all the images name in an array or session.
Like my HTML CODE is this
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="80%" border="1" align="center">
<tr>
<td width="52%">Text 1 </td>
<td width="48%">Text2</td>
</tr>
<tr>
<td><img src="blog_header4.jpg" width="200" height="150" /></td>
<td><img src="blog_header5.jpg" width="200" height="150" /></td>
</tr>
</table>
</body>
</html>
How can i do this??Any idea
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Dec 19, 2006 11:27 pm
Code: Select all
preg_match_all('#<img src="([^"]+)#i', $source, $matches);
echo '<pre>';
print_r($matches);
Enjoy,
eshban
Forum Contributor
Posts: 184 Joined: Mon Sep 05, 2005 1:38 am
Post
by eshban » Tue Dec 19, 2006 11:47 pm
which value i can put in
$source, $matches
please reply
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Dec 19, 2006 11:48 pm
$source is the html code, however you obtain it.. and $matches is what is outputted..
read the manual
preg_match_all()
Code: Select all
<?php
$source = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="80%" border="1" align="center">
<tr>
<td width="52%">Text 1 </td>
<td width="48%">Text2</td>
</tr>
<tr>
<td><img src="blog_header4.jpg" width="200" height="150" /></td>
<td><img src="blog_header5.jpg" width="200" height="150" /></td>
</tr>
</table>
</body>
</html>';
preg_match_all('#<img src="([^"]+)#i', $source, $matches);
echo '<pre>';
print_r($matches[1]);
?>
Outputs
Code: Select all
Array
(
[0] => blog_header4.jpg
[1] => blog_header5.jpg
)
eshban
Forum Contributor
Posts: 184 Joined: Mon Sep 05, 2005 1:38 am
Post
by eshban » Wed Dec 20, 2006 12:02 am
thank you so much