I’m using mb_strtolower to make a string lowercase, but sometimes text contains urls with upper case. And when I use mb_strtolower, of course the urls changing and not working.
How can I convert string to lower without changin urls?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since you have not posted your string, this can be only generally answered.
Whenever you use a function on a string to make it lower-case, the whole string will be made lower-case. String functions are aware of strings only, they are not aware of the contents written within these strings specifically.
In your scenario you do not want to lowercase the whole string I assume. You want to lowercase only parts of that string, other parts, the URLs, should not be changed in their case.
To do so, you must first parse your string into these two different parts, let’s call them
textandURLs. Then you need to apply the lowercase function only on the parts of type text. After that you need to combine all parts together again in their original order.If the content of the string is semantically simple, you can split the string at spaces. Then you can check each part, if it begins with
http://orhttps://(is_url()?) and if not, perform the lowercase operation:To have this code to work, you need to define the
is_not_url()function. Additionally, the original text must contain contents that allows to work on rudimentary parsing it based on the space separator.Hopefully this example help you getting along with coding and understanding your problem.