string manipulation strlen and chr

Problem

You want to perform string manipulation with PHP.



Solution

Following on from the intro post, see the example tab for some more demos on PHP string manipulation.



Example


Counting the number of characters in a string:

strlen

$ php -q<<EOT
<?php

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

?>
EOT

11

Converts an ASCII code to a character:

chr

$ php -q<<EOT
<?php

echo(chr(65)."n");

?>
EOT

A



Reference

[tags]PHP strlen, PHP chr, PHP Coding School[/tags]



Leave a Reply

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