Results 1 to 7 of 7

 

Thread: Removing forward slashes / from a string in PHP

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    401
    Thanks
    3
    Thanked 7 Times in 7 Posts


    hey there.. been playing with mod_rewrite to make my pages more search engine friendly but some of the categories my script serves up contain the '/' character, which stops the server being able to find the script.

    I've tried

    $string=str_replace("/","",$string);

    but it doesn't seem to do anything. Anybody got any ideas?
    thanks,
    jonny

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    401
    Thanks
    3
    Thanked 7 Times in 7 Posts
    oh yes, and i've the same problem in a perl script should anyone be able to suggest the fix for that..

  3. #3
    loquax's Avatar
    www.onelittleduck.co.uk

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Swansea
    Posts
    2,804
    Thanks
    45
    Thanked 163 Times in 92 Posts
    Try

    http://www.zend.com/manual/function.stripslashes.php

    echo stripslashes($str);

    Jason

  4. #4
    Avoiding real work

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Buckinghamshire
    Posts
    1,373
    Thanks
    0
    Thanked 0 Times in 0 Posts
    stripslashes probably won't work - it removes the \ character not the /.

    There's no reason why
    PHP Code:
    $string=str_replace("/","",$string); 
    shouldn't work.

  5. #5
    Avoiding real work

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Buckinghamshire
    Posts
    1,373
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just though why it might not work - the / probably needs to be escaped, so try -

    PHP Code:
    $string=str_replace("\\/","",$string); 
    and the same possibly goes for Perl - I think its something to do with regular expressions.

  6. #6
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    401
    Thanks
    3
    Thanked 7 Times in 7 Posts
    hmm yeah that's what i thought. I fixed the prob in perl - I had to use \/ not / but it doesn't seem to work in php for some reason..


    ....ug sorry im being a right muppet, doing the str_replace in a different bit of code to the one displaying the link! tsk tsk.. well thanku everyone all the same!

  7. #7
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    2,448
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One thing for the future, try using single quotes (') rather than double ('') as php doesn't check for escape chars etc in single quoted strings. It also doesn't check for inserted variables, so single quoted strings are quicker if you don't need then.

    e.g.
    Code:
    <?
    $val='hello';
    echo "$val world\n";
    echo '$val world\n';
    ?>
    Would print: -
    Code:
    Hello World
    $val world\n
    (\n is a new-line character)



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Anyone anygood with xml, php, mysql and Affiliate Window
    By AnnonnyMouse in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 23-09-04, 11:00 AM
  2. php: find string length
    By morleymouse in forum Programming
    Replies: 2
    Last Post: 25-06-04, 11:47 AM
  3. how to shorten a string (php)
    By morleymouse in forum Programming
    Replies: 3
    Last Post: 27-03-04, 04:35 PM

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
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2