FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Extract all img tag from a template file





Eneru
hi guys, if you have an idea can you help me please?
I want to get all <img> tag in my template file and append an additional string to the "src" of the tag.

Example:
Code:
<img src="images/<image_file>"><img src="images/<image_file>"> and so on...


i want to be able to add "themes/default/" to the src so it will become src="themes/default/images/<filename_here>"..any ideas?

I need a PHP function to do this. thanks Smile
sonam
If you want replace all tags in your template maybe is better to use Notepad or some other text/script editor with find and replace function then build PHP script.

Sonam
Eneru
sonam wrote:
If you want replace all tags in your template maybe is better to use Notepad or some other text/script editor with find and replace function then build PHP script.

Sonam


Thank you for your advice but I need it done using PHP. I am using a template class and I need to dynamically change the src's. If i have like 1k pages the notepad thing won't work, it's just alot.
sonam
Maybe this can help!

Code:
<?php
// create string from your template
$template = '<html>
<head>
<title>TEMPLATE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Some text!!!</p>
<p><img src="images/line.jpg" width="650" height="1"></p>
<p>SOMETHING!!!</p>
<p><img src="images/line2.jpg" width="650" height="1"></p>
</body>
</html>';

// replace part of your string
$template = str_replace("images/", "themes/default/images/", $template);

// echo template
echo $template;
?>

Sonam
Eneru
Thanks for this! Smile




Cheers!
Related topics
Site Nav Suggestions...
Tutorial: Image Rollovers w/ Javascript
PHP Tutorials
Any thing suit for beginners better than FrontPage
UBB Code / Smiley Parsing
Wanted: JS/Greasemonkey script...
Dynamic Signatures for Sale!
Need help with htaccess
problem creating on-the-fly jpeg thumbnails
A img tag that hold's HTML infromation
Frames for any resolution
missing template file error message
looking for a games ssite template
How to create template with DreamWeaver?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.