Monday, November 17, 2014

It uses the same code and the box in a function.


Attention PHP 5.5.0, some probably used in this tutorial SQL extensions may be obsolete and will be removed help link in the future, so you must adapt the code! Examples here.
How to truncate text with ellipsis with the substr function. Substr function to return a chain segment. Max_caracteres = $ 30; : Number of characters, here $ 30 description = "...."; : Description. if (strlen ($ description)> $ max_caracteres) to test whether help link the text length does not exceed the maximum number of character. $ Description = substr ($ description, 0, $ max_caracteres); : Selection of the maximum number of characters from the beginning of the phrase. $ Position_espace = strrpos ($ description, help link ""); : Retrieve the position of the last space not to cut a word. $ Description = substr ($ description, 0, $ position_espace); The sentence is reformatted to stop in space. $ Description help link = $ description "...."; : Adding ellipsis. echo "$ description"; Displays the truncated description. Example: <? Php $ max_caracteres help link = 30;? $ Description = "How to truncate a sentence by ellipses with the substr function."; // Check if the text length exceeds the limit if (strlen ($ description)> $ max_caracteres) {// Selection of the maximum character $ description = substr ($ description, 0, $ max_caracteres); // Retrieve the position of the last space (in order to avoid truncating a word) = $ position_espace strrpos ($ description, ""); $ Description = substr ($ description, 0, $ position_espace); // Add "..." $ description = $ description. "..."; } Echo "$ description"; I need regular.>
It uses the same code and the box in a function. <? Php function truncate ($ description) {// number of characters to display max_caracteres = $ 30; // Check if the text length exceeds the limit if (strlen ($ description)> $ max_caracteres) help link {// Selection of the maximum help link character $ description = substr ($ description, 0, $ max_caracteres); // Retrieve help link the position help link of the last space (in order to avoid truncating a word) = $ position_espace strrpos ($ description, ""); $ Description help link = substr ($ description, 0, $ position_espace); // Add "..." $ description = $ description. "..."; } Return $ description; } $ Text = "How help link to truncate a sentence by ellipses with the substr function."; // Echo the function truncate ($ text) on appeal; I need regular.>
View / leave a comment (0) | Report a problem in the same theme "PHP functions" How forbidden words in a text string or a function ltrim (), rtrim (), trim () Remove spaces at the beginning and end of the string function explode. How to split a string based on a separator function strlen (). How to know the size of a string str_replace function. How to replace a word with another in php
"Create Site" HTML-XHTML "CSS" PHP Language PHP variables in PHP PHP code PHP RSS "MySQL" AJAX "Create a dynamic CMS special free" JavaScript "version" Create the site Site "functions" Generators
Partners create a website create a website Create a website help link Create a website Create a free website Free Site Forum

No comments:

Post a Comment