gio
gio

Reputation: 3

reliably detecting line breaks in php

I'm going to build a wee batch search field where someone can enter/paste in a bunch of keywords separated by a linebreak, they might be copied in from excel, word or where-ever.

So I plan to use php to explode() that input and loop through it for an SQL search.

Do I need to do anything special to reliably detect the line breaks - my understanding is that the character can be different depending on where it's pasted from.

Upvotes: 0

Views: 145

Answers (1)

EboMike
EboMike

Reputation: 77762

Depending on where you got the string from, it's either \n, \r, or \r\n. If you explode on both \r and \n (and ignore empty matches), you should be fine.

Upvotes: 2

Related Questions