How to Check if String Contains Line Break in PHP?

03-Apr-2023

.

Admin

How to Check if String Contains Line Break in PHP?

Hi Dev,

Here, I will show you how to works how to check if string contains line break in php?. This article goes in detailed on how do i check if string contains line break php?. we will help you to give example of check a given value contains line break in php. step by step explain check if string contains a line break in php.

There are example to php check if string contains line break. in this example, we will use to strpos() function to Check if String Contains line break. so Let's the following example with output.

Example 1


index.php

<?php

$string = 'Hello world break found ';

if(strpos($string, "\n") !== FALSE) {

echo 'New line break found';

}

else {

echo 'Not Found';

}

?>

Output:

Not Found

Example 2

index.php

<?php

$string = 'Hello world

break found ';

if(strpos($string, "\n") !== FALSE) {

echo 'New line break found';

}

else {

echo 'Not Found';

}

?>

Output:

New line break found

I hope it could help you...

#PHP