Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
/ SmartSubstr Public archive

A smart PHP Substring function to avoid breaking words

License

Notifications You must be signed in to change notification settings

Pagawa/SmartSubstr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

SmartSubstr

Description

SmartSubstr is a PHP Substring function to avoid breaking words.

The function has 4 parameters :

  • $str (required) : The input string.
  • $maxLength (required) : Maximum number of characters that will be returned.
  • $separator (optional, default value is " " / space) : The boundary string.
  • $tail (optional, default value is "...") : If $maxLength is reached, this string will be added after the result.

Quick Example

<?php

require 'Pagawa/SmartSubstr/smartSubstr.php';

$example = "Lorem ipsum dolor sit amet, consectetur adipisicing";

# Without SmartSubstr
echo mb_substr($example, 0, 45) . '...';

echo "\n\n";

# With SmartSubtr
echo smartSubstr($example, 45);

This above example will output :

Lorem ipsum dolor sit amet, consectetur adipi...

Lorem ipsum dolor sit amet, consectetur...

Requirements

PHP 4 (>= 4.0.6) or PHP 5 (>= 5.0.0)

Contributing

All issues or pull requests must be submitted through GitHub.

  • To report an issue or a feature request, please use GitHub Issues.
  • To make a pull request, please create a new branch for each feature or issue.

ChangeLog

  • 2014-04-08 - First commit

About

A smart PHP Substring function to avoid breaking words

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages