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

Technorati Tags: , ,



Most Viewed


Leave a Reply


Search engine optimization by SEO Design Solutions