Thesubstr_count()function returns the number of times one string occurs within another. Its prototype follows: int substr_count(string str, string substring) The following example determines the number of times an IT consultant uses various buzzwords in his presentation: <?php $talk = <<< talk foreach($buzzwords as $bw) { This returns the following: -------------------------------------------- Replacing a Portion of a String with Another String Thesubstr_replace()function replaces a portion of a string with a replacement string, beginning the substitution at a specified starting position and ending at a predefined replacement length. Its prototype follows: string substr_replace(string str, string replacement, int start [, int length]) Alternatively, the substitution will stop on the complete placement ofreplacementinstr. There are several behaviors you should keep in mind regarding the values ofstartandlength:
Suppose you built an e-commerce site and within the user profile interface you want to show just the last four digits of the provided credit card number. This function is ideal for such a task: <?php This returns the following: -------------------------------------------- Please check back next week for the conclusion to this article.
blog comments powered by Disqus |