Gossamer Forum
Home : General : Perl Programming :

another regex

Quote Reply
another regex
This is to parse image through customers's leaving message in message board...

Code:


if ( $comments =~ /\[img\/(\d+)\/(\d+)\]/ig){


$comments=~ s/\[img\/(\d*)\/(\d*)\](.*)\[\/img\]/<img src="$3" border="0" width="$1" height="$2">/ig;}


else{$comments=~ s/\[img\](.*)\[\/img\]/<img src="$1" border="0" width="192" height="60">/ig;}
which limits the customer adding tag as any forum but you can set the image size throuth

[img/123/22]image link[/img]

However, the 123 and 22 may over the size of table width say 580 .

So, How to limit $1(i.e. 123 ) not getting bigger than 580 and replace it with width="580" if it is over the limit..

Is there a better way to present the codes(seemingly a little bit clumsy??)