In PHP I want to insert a white space after each < but only if there is no white space already.
I tried:
preg_replace('/<\S/', '< ', $data);
This works for a single < but if I have << it does not work anymore.
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.
As @Summoner pointed out, your current regex replaces the character after a
<with a space rather than inserting one. Well, both problems (the replacement and the code not working on something like<<) can be fixed with one solution: lookaheads. Try this code: