...

View Full Version : removing all single quotes from a string



sradha
11-15-2010, 06:08 AM
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.

Keleth
11-15-2010, 06:13 AM
str_replace("'", "", $string)

sradha
11-15-2010, 07:31 AM
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.

poyzn
11-15-2010, 07:37 AM
$path_array = explode('/', 'http://www.abc.ghj/forms/generalpeople/News.txt');
$filename = end($path_array);
echo $filename;


or



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

sradha
11-15-2010, 08:15 AM
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.

poyzn
11-15-2010, 08:26 AM
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 :)

abduraooft
11-15-2010, 08:42 AM
$str='http://www.abc.ghj/forms/generalpeople/News.txt';
echo $filename=basename($str);

poyzn
11-15-2010, 09:12 AM
$str='http://www.abc.ghj/forms/generalpeople/News.txt';
echo $filename=basename($str);


oh,I've forgotten about basename()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum