My php is weak and I'm trying to change this string:
http://www.example.com/backend.php?/c=crud&m=index&t=care ^
to be:
http://www.example.com/backend.php?c=crud&m=index&t=care ^
removing the /
after the backend.php?
. Any ideas on the best way to do this?
Thanks!
Explanation: In PHP to remove characters from beginning we can use ltrim but in that we have to define what we want to remove from a string i.e. removing characters are to be known. $str = "geeks" ; // Or we can write ltrim($str, $str[0]);
Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.
Answer: Use the PHP str_replace() function You can use the PHP str_replace() function to replace all the occurrences of a word within a string.
Definition and Usage. The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string.
I think that it's better to use simply str_replace, like the manual says:
If you don't need fancy replacing rules (like regular expressions), you should always use this function instead of ereg_replace() or preg_replace().
<? $badUrl = "http://www.site.com/backend.php?/c=crud&m=index&t=care"; $goodUrl = str_replace('?/', '?', $badUrl);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With