Posts made by Joseph Rézeau

Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

Muchas gracias, Eloy,approve

However, it only works with the first syntax. If I want to return the first 30 characters of string $mystring:

$return = $textlib->substr($mystring, 0, 30);

works ok

$return = moodle_substr($mystring, 0, 30);

does not work.

Joseph

PS.- In the meantime I had used this small function, which works welll:

 function utf8_substr($str, $from, $len){

 return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.
 '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',
 '$1',$str);
 }


Moodle in English -> General developer forum -> how to use utf8_substr ?

by Joseph Rézeau -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators
I need to use a substr function on non-latin character language. Of course, the php function substr() does not work correctly, so I need to use the utf8_substr() which exists in lib/typo3\class.t3lib_cs.php. But how do I "call" this function? Do I need to put a GLOBAL or INCLUDE in my php file so that it does not tell me "Call to undefined function utf8_substr()"?
Thanks in advance,
Joseph
Average of ratings: -