$string = 'Some Text .... 1. 2 .3.  Buy';
$string = preg_replace('~[^0-9]+~','',$string);
echo $string;
// 123 
function compresscss ( $data, $url ) {
        global $current_css_url;
        $current_css_url = $url;
        /* remove comments */
        $data = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $data);
        /* remove tabs, spaces, new lines, etc. */
        $data = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $data);
        /* remove unnecessary spaces */
        $data = preg_replace('/[ ]+([{};,:])/', '\1', $data);
        $data = preg_replace('/([{};,:])[ ]+/', '\1', $data);
        /* remove empty class */
        $data = preg_replace('/(\}([^\}]*\{\})+)/', '}', $data);
        /* remove PHP code */
        $data = preg_replace('/<\?(.*?)\?>/mix', '', $data);
        /* replace url*/
        $data = preg_replace_callback('/url\(([^\)]*)\)/', 'replaceurl', $data);
        return $data;
}

 

Friday, 30 June 2023 19:44

How to trim String text in php

For example we have text

<strong>
                            The Times
                        NY
                </strong>

 But good result need be

<strong>The Times NY</strong>

 I make regexp in php

function trim_text($str)                             
{                                                    
    return trim(preg_replace('/\s{2,}/', ' ', $str));                                                 
}