string manipulation substr and trim

Problem

Substituting and trimming string variables in PHP.



Solution

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

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



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



Reference

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



Leave a Reply

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