A better substring function

1
2
// This function does not destroy i.e. html entities which could lead to a wrecked design or strange custom chars showing on a site
// It iterates backward through the string and checks for a space or a minus sign and cuts the string at that position.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

2 Responses

$subs = preg_split("/[s,-]+/", $string, $len);
echo implode(, $subs);

// ... no?
implode(" ", $subs); // ... no?

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.