00 Votes

PHP: Line break and strpos

Question by Compi | 2012-06-20 at 21:41

I am at a loss. I want to find the position of a line break within a string using strpos() in PHP. Up to now, I have already experimented with:

strpos($string,'\n');

But somehow, it does not seem to be working. Now, I am even thinking about using nl2br() to get to the breaks in some way, but that is nevertheless far too complicated and with this solution, you should not ask for the performance anyway.

Thus, maybe someone knows how to do that?

ReplyPositiveNegative
1Best Answer1 Vote

Certainly, your approach is not that bad. But you have to use double instead of single quotes:

strpos($string, "\n");

Otherwise, PHP interprets the \n not as a line break but as the characters "\" and "n".

PS: And please, forget about the nl2br() solution quickly... ;)
2012-06-21 at 15:29

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.