PHP

A sort of teaser function splitting inbetween two words


/**
* Get the position in a text inbetween two complete words just below
* a limit if the text is longer than the limit.
*
* @param unknown_type $text
* @param unknown_type $limit
* @return unknown
*/
function _get_complete_word($text, $limit = 5000) {

$text_lenght = strlen($text);

if ($text_lenght <= $limit) {

return $text_lenght;

}else{

preg_match_all("/ /ui", $text, $matches, PREG_OFFSET_CAPTURE);

foreach ($matches[0] as $key => $value) {
if ($value[1] >= $limit) {
return ($key == 0 ?

How to filter strings and just allow a-z and A-Z and /or numbers

This is how you can filter strings and just allow a-z and A-Z and /or numbers.

<?php
//Allow only a-z, A-Z and 0-9
         
if(ctype_alnum($value) > 0) {
           
$tags_array[] = $value;
          }

//Allow only a-z and A-Z
         
if(ctype_alpha($value) > 0) {
           
$tags_array[] = $value;
          }
?>

Read more about ctype_alnum() or ctype_alpha()

Pages