- print_r: documentation ( source)
- preg_replace: documentation ( source)
<?php
$var = array(
'#tag',
'text #tag text',
'text #tag',
'text#tag',
);
$res = preg_replace('/(?<\s)#\S{1,24}+/u', '<$0>' , $var);
print_r($res);
echo preg_replace('/(?<\s)#\S{1,24}+/u', '<$0>' , '#111 тапинамбур#222 #333 #444');