PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 26th, 2002, 03:28 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
String Replace Problem

OK, another minor problem - let's hope it is as easy to solve as the first...

I have a string which might look something like the following:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $string = "This is my favourite picture, [img=funny.gif]My Family[/img]. Do you like it? How about this: [img=test.gif]Cool image[/img] How about that one?";
  4. ?>

What I want to do is replace all the information in the [ img] (space added in the tag to prevent eF from picking it up) tags with the html <img> tag so that the attribute in the tag after the = is the image source, and the information between the tags is the alternative text, e.g.:
php Code:
Original - php Code
  1.  
  2. [img=file.gif]Alt Text[/img]
  3.  
  4. becomes:
  5.  
  6. <img src="file.gif" alt="Alt Text" />

I've tried using eregi_replace(), but I'm really not good with patterns and am not exactly sure how to do it. Any ideas would be great. Thanks in advance.

Reply With Quote
  #2  
Old September 26th, 2002, 03:47 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: String Replace Problem

$string = preg_replace("/[img=(.*?)](.*?)[/img]/", "<img src="\1" alt="\2">", $string);

Reply With Quote
  #3  
Old September 26th, 2002, 04:38 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: String Replace Problem

Wow! Thank you very much. I really should learn how to do patterns properly.... very useful.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > String Replace Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway