$x = "''xx''";
echo $x, "
";
echo trim($x, "'");
In this program i want to trim only one single quote from start and one from end. Trim removes all the single quotes from starting and end.
I wish it would remove just one quote.
$x = "''xx''";
echo $x, "
";
echo trim($x, "'");
In this program i want to trim only one single quote from start and one from end. Trim removes all the single quotes from starting and end.
I wish it would remove just one quote.
$x = preg_replace("/^'?(.*?)'?$/", '$1', $x);
Or if you have an aversion to using regular expressions:
if (substr($x, 0, 1) === "'") {
$x = substr($x, 1);
}
if (substr($x, -1) === "'") {
$x = substr($x, 0, -1);
}