|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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! |
|
#3
|
|||
|
|||
|
Thank you very much! It's working!!!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Convert word to image in cgi script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|