user1656273
user1656273

Reputation:

Enter next line by verifying if string length has reached the specified number

I want to create a condition in PHP to check whether the length of the string has reached the specified value and if the condition is true then show rest of the characters on the next line. The string is passed from a form using POST method.

Upvotes: 1

Views: 141

Answers (3)

Teena Thomas
Teena Thomas

Reputation: 5239

considering the specific length is 10

 if(strlen($_POST['str']) > 10)
    echo "\n". substr($_POST['str'],10);

Upvotes: 1

Zevi Sternlicht
Zevi Sternlicht

Reputation: 5399

$max_length = 100;
$string = 'mystring'; // or whatever 

if(strlen($string) > $max_length){
    $sub_str = substr($string, $max_length);
}

echo $sub_str on a new line if $sub_str is set.

Upvotes: 1

Martin Bean
Martin Bean

Reputation: 39389

Are you looking for the wordwrap() function?

Upvotes: 1

Related Questions