Given that PHP is essentially a vehicle for the deployment of web content, and that much web content is text based, it should come as no surprise that PHP includes a range of features designed to ease the task of manipulating text and strings.
In this chapter we will explore a number of the functions and techniques provided by PHP to enable you, as a web developer, to perform tasks such as changing the case of a string, replacing one part of a piece of text with another peice piece of text, searching text and much more.
== Changing the Case of a PHP String ==
PHP provides a number of functions that enable changes to be made to the case of text contained in a string. These functions all take the string to be modified as an argument and return the modifed modified string. It is important to note that these functions are ''nondestructive'', that is to say they do not make any change to the original string, they simply return a completely new string containing the modification leaving the original string unaltered. The returned string can be assigned to a new variable or used directly in another function (such as a ''print'' or ''echo''):
<pre>
== Converting to and from ASCII Values ==
PHP provides the ability to work with ASCII (American Standard Code for Infomration Information Interchange) values. ASCII maps numerical character codes to standard, human readable characters. There are 127 ASCII characters representing the letters of the alphabext alphabet (including upper and lower case), numbers and various punctuation marks. There is also an extended character set which contains 255 characters.
PHP provides two functions for the purpose of converting to and from ASCII codes:
* '''ord()''' - Takes a character as an argument and returns the ASCII code corresponding to that character.
* '''chr()''' - Takes an ASCII code as an argument and retuns returns the character equivalent.
The following example converts a character to an ASCII code and then reverts it back to the character:
== Printing Formatted Strings in PHP ==
Exception encountered, of type "Error"
[2eaae9df] /index.php/Special:MobileDiff/7771 Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDiffFormatter.php(99): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): InlineDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDifferenceEngine.php(117): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): InlineDifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(241): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(135): SpecialMobileDiff->showDiff()
#14 /var/www/techotopia/extensions/MobileFrontend/includes/specials/MobileSpecialPage.php(53): SpecialMobileDiff->executeWhenAvailable()
#15 /var/www/techotopia/includes/specialpage/SpecialPage.php(384): MobileSpecialPage->execute()
#16 /var/www/techotopia/includes/specialpage/SpecialPageFactory.php(553): SpecialPage->run()
#17 /var/www/techotopia/includes/MediaWiki.php(281): SpecialPageFactory::executePath()
#18 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#19 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#20 /var/www/techotopia/index.php(41): MediaWiki->run()
#21 {main}