How to trim String text in php

Written by  Friday, 30 June 2017 19:44

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));                                                 
}

 

201 Read

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

6 comments

  • Comment Link prada eyeglasses Sunday, 11 February 2018 05:17 prada eyeglasses

    There are definitely numerous details like that to take into consideration. That is a great level to bring up. I supply the thoughts above as general inspiration however clearly there are questions just like the one you convey up the place the most important thing will likely be working in trustworthy good faith. I don?t know if greatest practices have emerged around issues like that, however I am positive that your job is clearly identified as a fair game. Both boys and girls really feel the influence of only a second抯 pleasure, for the rest of their lives.

  • Comment Link yeezy boost 350 Saturday, 17 February 2018 01:33 yeezy boost 350

    Oh my goodness! a tremendous article dude. Thanks However I'm experiencing subject with ur rss . Don抰 know why Unable to subscribe to it. Is there anyone getting an identical rss downside? Anybody who is aware of kindly respond. Thnkx

  • Comment Link yeezy boost Monday, 19 February 2018 09:13 yeezy boost

    I would like to show thanks to you for bailing me out of such a incident. As a result of scouting throughout the search engines and getting thoughts which are not productive, I believed my entire life was done. Existing without the presence of strategies to the issues you've sorted out all through your entire article content is a crucial case, and those that might have in a negative way damaged my entire career if I had not come across the blog. That knowledge and kindness in touching all the details was important. I am not sure what I would have done if I had not encountered such a step like this. I am able to now look ahead to my future. Thanks a lot very much for this impressive and result oriented guide. I will not think twice to recommend your blog to any person who desires guide on this topic.

  • Comment Link nmd uk Wednesday, 21 February 2018 01:46 nmd uk

    I want to show appreciation to the writer for rescuing me from this type of situation. After surfing around throughout the the web and obtaining methods which are not beneficial, I thought my entire life was done. Existing without the strategies to the issues you've resolved through the article is a crucial case, and those that might have badly damaged my career if I hadn't encountered the blog. The mastery and kindness in handling the whole thing was vital. I don't know what I would've done if I had not discovered such a solution like this. I'm able to now look forward to my future. Thanks so much for this reliable and sensible help. I won't hesitate to endorse your blog post to anyone who should receive care about this issue.

  • Comment Link nmd Saturday, 24 February 2018 04:01 nmd

    Can I just say what a aid to find somebody who actually is aware of what theyre speaking about on the internet. You positively know the right way to deliver a problem to mild and make it important. Extra people need to read this and understand this facet of the story. I cant imagine youre no more popular because you definitely have the gift.

  • Comment Link nike air presto Saturday, 03 March 2018 04:10 nike air presto

    There are some fascinating deadlines in this article but I don抰 know if I see all of them heart to heart. There is some validity however I'll take hold opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as properly

Related items

  • [solved] How to delete text symbol from php line?
    in PHP
    $string = 'Some Text .... 1. 2 .3.  Buy';
    $string = preg_replace('~[^0-9]+~','',$string);
    echo $string;
    // 123 
  • [php] How to make function for compress css using regular expression
    in PHP
    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;
    }