SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    str_replace and extra variables

    I want to be able to make an [image] tag for users to be able to hotlink images

    I came up with

    $content = str_replace("[image]","<image src='",$content);
    $content = str_replace("[/image]","' border=0>",$content);

    This is not very secure.

    How could I change this to a secure [image=imgurl] type tag?

    Thanks in advance.

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    It would be easier to use regex for the [image=$imgurl] but why? vBulletin uses [img]$imgurl[/img]. And specific reason you want to use the more advanced syntax?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The above I used someone could only put [image] which would mess the HTML a bit with a broken tag.

    How would I change my current code to stop this?

    Thanks

  4. #4
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure the link ends with .jpeg, .gif.... before you do the above.

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
     $pattern "#\[image\](.*?)\[/image\]#si";
     
    $replace '<img src="$1" border="0" />';
     
     
    $content preg_replace($pattern$replace$content); 

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! Works great.

  7. #7
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Missing the alt tag
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •