Tag: PHP String Function

String Function in PHP

nl2br(): The nl2br() function adds the tag if it finds the carriage return (n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with tag. Here is the syntax of the nl2br() tag: [php] …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-function-in-php/

String Functions in PHP [heredoc syntax]

The heredoc syntax: In addition of the single quote and double quote syntaxex, PHP provides another way to specify a string called heredoc syntax. This syntax turns out to be a extremely useful for specifiying large chunks of variable-interpolated text, because it spares you from the need to escape internal quotation marks. It is especially …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-functions-in-php-heredoc-syntax/

Display first sentence with PHP

To display the first sentence of the paragraph with PHP. Use this code Code [php] function first_sentence($content) { $pos = strpos($content, ‘.’); if($pos === false) { return $content; } else { return substr($content, 0, $pos+1); } } [/php] Invoke the function like [php] echo first_sentence($content); [/php]

Permanent link to this article: https://blog.openshell.in/2011/07/display-first-sentence-with-php/