string manipulation substr and trim

[problem]

Substituting and trimming string variables in PHP.

[/problem]

[solution]

Similar to Perl, PHP has an extensive library of functions.

See the example tab for a few simple examples, showing the basic syntax.

[/solution]

[example]

substr

$ php -q<<EOT
<?php

echo(substr("Hello World",0,4)."n");

?>
EOT

Hell

trim

 $ php -q<<EOT
<?php

echo(trim(" Hello World ")."n");

?>
EOT

Hello World

[/example]

[reference]

[tags]PHP substr, PHP trim, PHP Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *