Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search and replace in strings?

    Hello!

    I would like to fetch a database entry's text with php and search it after a string with certain markers around it, for example %, so that PHP can remake it to a hyperlink to another place with the words enclosed inside the %:s in the link, when all the text is outputted in the browser.

    Basically I need a clue as to what function can accomplish this so I can look in to how to do it exaclty, cause right now I don't have a clue

    Very thankful for help!

    /Magnus
    Last edited by Priapulidae; 01-08-2004 at 08:34 PM.

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey there,

    Your best bet is to surround it with something a little more unique, sure as something like this:

    Code:
    <url=>http://www.codingforum.com</url=>CodingForums</url>
    You could then do a search/replace using something like str_replace() (which convenientlysupports arrays too ) like so:
    PHP Code:
    $string str_replace('<url=>','<a href="',$string);
    $string str_replace('</url=>','">',$string);
    $string str_replace('</url>','</a>',$string); 
    This is more or a PHP question, so i'll move it over there for you

    Jee
    Last edited by Jeewhizz; 01-08-2004 at 07:24 PM.
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    The first thing you need to do is read our posting guidelines section 2

    http://www.codingforums.com/postguide.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks alot Jeewhizz! str_replace() seems to be the kind of thing I'm looking for.

    I changed the subject to a hopefully more descriptive one, since I didn't know what I was lookin for I had a hard time naming the post :P


  •  

    Posting Permissions

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