RE: [PHP] link on user uploaded pic
| From: | Brad Fuller | Date: | Thu, 29 Mar 2007 17:37:10 +0000 |
| Subject: | RE: [PHP] link on user uploaded pic | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-251652@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Brad Fuller [mailto:bfuller@cpacampaigns.com]
> Sent: Thursday, March 29, 2007 1:24 PM
> To: 'Tana'; php-general@lists.php.net
> Subject: RE: [PHP] link on user uploaded pic
>
> > -----Original Message-----
> > From: Tana [mailto:tana@devtux.hu]
> > Sent: Thursday, March 29, 2007 1:02 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] link on user uploaded pic
> >
> > Hi
> >
> > which is the best way to change this code
> >
> > <img src="images/user_upload/akarmi.jpg">
> >
> > to
> >
> > <a href="images/user_upload/bp_akarmi.jpg"><img
> > src="images/user_upload/akarmi.jpg"></a>
> >
> > in html ?
> >
> >
> > ----------------------------
> > Tana
>
>
> <?php
>
> $imgTag = '<img src="images/user_upload/akarmi.jpg">';
>
> echo preg_replace('/<img src="images\/user_upload\/(.*?)">/',
> '<a
> href="images/user_upload/bp_$1"><img
> src="images/user_upload/$1"></a>',
> $imgTag);
>
> ?>
>
> -B
Oops, in that last post part of that code is redundant (forgot about $0 ;)
<?php
$imgTag = '<img src="images/user_upload/akarmi.jpg">';
echo preg_replace('/<img src="images\/user_upload\/(.*?)">/', '<a
href="images/user_upload/bp_$1">$0</a>', $imgTag);
?>
Enjoy,
-B