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 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    God's Own Country
    Posts
    87
    Thanks
    6
    Thanked 0 Times in 0 Posts

    removing all single quotes from a string

    Hello

    I am using a function str_get_html().[ My aim is to get the hyperlink-url out of the string.The string is taken from database].The argument passed to str_get_html() is a string enclosed in single quotes. But if the string itself contains single quotes then an error is shown as it is unable to find the string termination point. I want to know how can I escape those single quotes.Is there some function for removing all single quotes.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Code:
    str_replace("'", "", $string)

  • #3
    New Coder
    Join Date
    Feb 2010
    Location
    God's Own Country
    Posts
    87
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for the help.


    I have one more issue. If I have a url like "http://www.abc.ghj/forms/generalpeople/News.txt", how cant I get the last part of url alone ,that is News.txt. I need to get the content that comes after the last slash.How can I split it.

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    PHP Code:
    $path_array explode('/''http://www.abc.ghj/forms/generalpeople/News.txt');
    $filename end($path_array);
    echo 
    $filename
    or

    PHP Code:
    preg_match('/\/([^\/]+)$/''http://www.abc.ghj/forms/generalpeople/News.txt'$match);
    echo 
    $match[1]; 

  • #5
    New Coder
    Join Date
    Feb 2010
    Location
    God's Own Country
    Posts
    87
    Thanks
    6
    Thanked 0 Times in 0 Posts
    thank you for the quick response..

    Which solution is the better one,according to you..The first method seems to be more understandable to me than the second one.

  • #6
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by sradha View Post
    thank you for the quick response..

    Which solution is the better one,according to you..The first method seems to be more understandable to me than the second one.
    so use the first method. As for me I would prefer the second one, cause it consist of only one function

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    $str='http://www.abc.ghj/forms/generalpeople/News.txt';
    echo 
    $filename=basename($str); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by abduraooft View Post
    PHP Code:
    $str='http://www.abc.ghj/forms/generalpeople/News.txt';
    echo 
    $filename=basename($str); 
    oh,I've forgotten about basename()
    Last edited by poyzn; 11-15-2010 at 12:27 PM.


  •  

    Posting Permissions

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