NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Small PHP preg_replace question.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-26-2006, 08:09 PM THREAD STARTER               #1 (permalink)
NamePros Member
 
agasonex's Avatar
Join Date: Feb 2006
Posts: 34
agasonex is an unknown quantity at this point
 



Small PHP preg_replace question.


Hi, i've never been too good with preg_replaces, and was wondering what I would use to replace
<img src="imageurl" border="0">
with
<a href="imageurl">imageurl</a>

Thanks for any help, will give rep. =)
__________________
~agasonex
agasonex is offline  
Old 02-26-2006, 10:55 PM   #2 (permalink)
NamePros Regular
 
nick's Avatar
Join Date: Jun 2004
Location: Iowa City
Posts: 703
nick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud of
 


Save The Children
PHP Code:
<?php
$string
="<img src=\"imageurl\" border=\"0\">";

$new explode('"',$string);
$new_string "<a href=\"$new[1]\">$new[1]</a>";

echo 
$new_string;
?>
tested and works (w/o using preg_replace tho)
__________________
formally ninedogger
------
Want to talk to a stranger? -->| Click Here | TalkToAStranger.com | <-- Meet New Friends
nick is offline  
Old 02-26-2006, 11:51 PM THREAD STARTER               #3 (permalink)
NamePros Member
 
agasonex's Avatar
Join Date: Feb 2006
Posts: 34
agasonex is an unknown quantity at this point
 



Thanks for the help, but it doesn't quite work with what I'm trying to do. Sorry about that, I should have been more specific.

I'm trying to get it on my forum so users can choose to have images replaced with a link to the image.
So it would have to be able to replace all of the "<img src="~~" of a text field.

Gave you a rep+ anyway though.
__________________
~agasonex
agasonex is offline  
Old 02-27-2006, 12:24 AM   #4 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Tested this, and it works:
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/171632-small-php-preg_replace-question.html

$blah 
'<img src="blahblah.gif" border="0">';

preg_match('/<img src="(.*?)" border="0">/si'$blah$matches);
$new preg_replace('@<img src=".*?" border="0">@si''<a href="'.$matches[1].'">'.$matches[1].'</a>'$blah);

echo 
$new;

?>
Eric is offline  
Old 02-27-2006, 12:40 AM THREAD STARTER               #5 (permalink)
NamePros Member
 
agasonex's Avatar
Join Date: Feb 2006
Posts: 34
agasonex is an unknown quantity at this point
 



Thanks, works perfectly.
__________________
~agasonex
agasonex is offline  
Old 02-27-2006, 01:04 PM   #6 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
No problem, glad to help
Eric is offline  
Old 02-27-2006, 01:08 PM   #7 (permalink)
NamePros Regular
 
Tree's Avatar
Join Date: Feb 2006
Location: Atlanta, GA, USA
Posts: 335
Tree will become famous soon enoughTree will become famous soon enough
 



I hope that when I grow up, I'll be as smart as SecondVersion
Tree is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Ask Questions the Smart Way Cyberian The Break Room 10 01-22-2006 05:16 PM
How'd They Do That? Simple PHP question MCDomains Programming 11 11-05-2005 01:04 AM
Looking to do small to mid-sized PHP / mySQL projects moondog For Sale / Advertising Board 0 10-31-2005 07:26 PM
Have a question it's either MYSQL or PHP. Coolprogram Programming 11 10-13-2005 01:14 AM
Javascript / PHP Question Zubair1 Programming 4 08-20-2005 08:55 AM

 
All times are GMT -7. The time now is 02:10 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger