Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

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 Dev Shed Forums Sponsor:
  #1  
Old July 22nd, 2001, 06:53 AM
Dimur Dimur is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Ukhta, Komi Republic, Russia
Posts: 5 Dimur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Convert word to image in cgi script

Hello!

I'm making a message board on cgi scripts.
And I want to make a simple function that converts some word in colons to specific image. For example instead of : picture: image picture.gif will appear. I think I need only some mark that means "any word". So if function finds any word in colons it replaces this word in colons with <IMG SRC="any word.gif">.

Can anybody help me?

Reply With Quote
  #2  
Old July 22nd, 2001, 10:40 AM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
looks like a little regex would do the trick:

Code:
$image =~ s/(.*):(\w+):(.*)/$1<img src="$2">$3/g;




This ain't perfect, but it should work OK. This will replace anything in a scalar surrounded by :: with the <img src=""> stuff.

So, "asdlkfsd sdflkfds:test:asfdlasdf; :test:" would become:

asdlkfsd sdflkfds<img src="test">asfdlasdf; <img src="test">

What it does: It looks for anything that's surrounded with : 's, with no whitespace before or in the string itself, and stores it in $2 for later.

Everything before $2 is stored in the first set of (), as $1, everything after $2 is stored in the third set of () as $3. The replacement then puts $1, then <img src="$2"> and finally $3 together, preserving the whole string. The /g modifier tells it do the match globally, as many times as it can and to ignore newlines.

Good luck!

Reply With Quote
  #3  
Old July 22nd, 2001, 12:14 PM
Dimur Dimur is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Ukhta, Komi Republic, Russia
Posts: 5 Dimur User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Thank you very much! It's working!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Convert word to image in cgi script


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
Stay green...Green IT