3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function truncate($input, $maxWords, $maxChars){ $words = preg_split('/\s+/', $input); $words = array_slice($words, 0, $maxWords); $words = array_reverse($words); $chars = 0; $truncated = array(); while(count($words) > 0) { $fragment = trim(array_pop($words)); $chars += strlen($fragment); if($chars > $maxChars){ if(!$truncated){ $truncated[]=substr($fragment, 0, $maxChars - $chars); } break; } $truncated[] = $fragment; } $result = implode($truncated, ' '); return $result . ($input == $result ? '' : '...'); } $query = 'google'; $content = " Sign in UploadSearch Guide Popular on YouTube Music Sports Gaming Movies TV Shows News Comedy Week Spotlight No channels found Loading subscriptions Channels for you The Ricky Gervais Channel YouTube Spotlight Al Jazeera English H+ The Digital Series Truthloader No channels found Loading subscriptions Browse channels Sign in to add channels to your guide and for great recommendations! Sign in › Featured Channels ABC News SubscribeSubscribedUnsubscribe CNN SubscribeSubscribedUnsubscribe RT SubscribeSubscribedUnsubscribe The New York Times SubscribeSubscribedUnsubscribe Associated Press SubscribeSubscribedUnsubscribe BuzzFeed Central SubscribeSubscribedUnsubscribe The Weather Channel SubscribeSubscribedUnsubscribe The Wall Street Journal SubscribeSubscribedUnsubscribe The Young Turks SubscribeSubscribedUnsubscribe SourceFed SubscribeSubscribedUnsubscribe see all Popular VICE SubscribeSubscribedUnsubscribe Nice Peter's Youtube SubscribeSubscribedUnsubscribe البرنامج ؟ .. مع باسم يوسف SubscribeSubscribedUnsubscribe JumbaFund SubscribeSubscribedUnsubscribe VlogBrothers SubscribeSubscribedUnsubscribe Auto-generated by YouTube SubscribeSubscribedUnsubscribe 12,269,230 Subscription preferences Loading... Loading... Working... News - Worldwide Browse Feed Videos Top Stories Play 0:56 Obama: Oklahomans inspire with courage by CNN 4,389 views | 22 hours ago 2:22 Residents grieve fallen officer by wlkytv 301 views | 6 hours ago 2:19 Forget Angelina Jolie: How Obamacare Endangers Your Breasts by ReasonTV 6,888 views | 3 days ago 0:53 Boston marathon runners complete last mile by Euronews 2,559 views | 1 day ago 0:55 Gay marriage France: Protestors clash with police in Paris by ITN 301 views | 7 hours ago 11:41 Top Naxal leader K Sudarshan may be behind the attack on Cong rally: Sources by ibnlive 301 views | 7 hours ago 8:45 Highlights: LA Galaxy vs Seattle Sounders FC by TheLAGalaxy 2,506 views | 12 hours ago Entertainment Play 2:14 La vie d'Adele (Blue is the Warmest Colour) Movie Clip - Festival de Cannes Winner 2013 by FilmIsNowEU 301 views | 8 hours ago 4:08 *SPECIAL EDITION* 'The Fresh Prince of Bel-Air' Rap - The Graham Norton Show May 30 BBC AMERICA by BBCAmericaTV 390,720 views | 2 days ago 0:19 Arrested Development Season 4 Clip - Security Cameras [HD] by NewOnNetflix 112,157 views | 3 days ago 2:05 Michael Douglas and Matt Damon in Behind the Candelabra | Cannes Film Festival by blacktreemedia 785 views | 2 days ago 2:19 Forget Angelina Jolie: How Obamacare Endangers Your Breasts by ReasonTV 6,888 views | 3 days ago 3:22 Exclusive: Vin Diesel Teases Fast 7! - HipHollywood.com by HipHollywood 2,042 views | 2 days ago 1:07 Roman Polanski back at Cannes with 'Venus in Fur' by AFP 347 views | 2 days ago Sports Play 8:45 Highlights: LA Galaxy vs Seattle Sounders FC by TheLAGalaxy 2,506 views | 12 hours ago 3:21 Miami Heat Vs Indiana Pacers - NBA Eastern Conference Finals 2013 Game 3 by NBASeasonPlayoffs 3,983 views | 12 hours ago 1:53 Digital Serve: Nadal, Sharapova Ready by ESPN 938 views | 1 day ago 1:40 Kings Shut Out Sharks For Series Lead by ESPN 1,958 views | 3 days ago 0:56 Falling Cable Hurts 10 NASCAR Fans by AssociatedPress 346 views | 9 hours ago 2:58 Flacco's Agent: Ravens Made Dumb Move by ESPN 4,340 views | 21 hours ago 2:43 Round 3 Recap: 2013 Crowne Plaza Invitational by pgatour 2,805 views | 1 day ago 3:46 MMA Live Extra: UFC 160 Fallout by ESPN 301 views | 4 hours ago 0:30 Suns To Name Hornacek New Coach by ESPN 916 views | 19 hours ago 1:33 Danica and Keselowski collide at Charlotte by NASCAR 1,404 views | 15 hours ago 30:06 UFC 160: Dana White Post-Fight Media Scrum by Karyn Bryant 30,197 views | 1 day ago 1:01 John Tortorella on Brad Richards - Post Game Comments - May 23, 2013 (HD) by HockeyWebCaster 31,736 views | 3 days ago Technology Play 2:26 Hulu Bidding War Welcomes KKR, Silver Lake by Bloomberg 785 views | 3 days ago 4:41 Curiosity - what's inside the cube winner video by 22CansOfficial 506,029 views | 1 day ago 3:40 BMW Pininfarina Gran Lusso Coupé - Exterior Design by SupercarHall 4,926 views | 2 days ago 1:50 Google Glass Photographer by gogrovo 607,503 views | 4 days ago 1:30 Watch: A car that runs on your tweets and Facebook likes by ibnlive 301 views | 13 hours ago 2:14 Iran-linked hackers probe U.S. energy firms by CNN 1,411 views | 2 days ago World Play 7:08 Trying to avoid an EU-China trade war - BUSINESS BULLETIN 05/27/2013 by france24english 209 views | 10 hours ago 1:19 World Economic Forum meeting in Jordan ends with session of Palestinian and Israeli leaders by JewishNewsOne 302 views | 21 hours ago 2:30 S Korean Former Comfort Women Cancel Meeting with Osaka Mayor by NTDTV 309 views | 3 days ago 2:06 Rockets hit Beirut's southern suburbs by AlJazeeraEnglish 6,885 views | 1 day ago 0:55 Gay marriage France: Protestors clash with police in Paris by ITN 301 views | 7 hours ago 11:41 Top Naxal leader K Sudarshan may be behind the attack on Cong rally: Sources by ibnlive 301 views | 7 hours ago 1:49 Colombia closer to peace deal by AlJazeeraEnglish 749 views | 16 hours ago Language: English Country: Worldwide Safety: Off Help Loading... Loading... Loading... About Press & Blogs Copyright Creators & Partners Advertising Developers Terms Privacy Policy & Safety Send feedback Try something new! Loading... Working... Sign in to add this to Watch Later Sign in to add this to Watch Later Added to Private videos will be skipped if viewers don't have access, but playlist notes are publicly visible. Back to list Added to playlist: Private videos will be skipped if viewers don't have access, but playlist notes are publicly visible. Add an optional note150 Add note Saving note... Note added to: Error adding note: Click to add a new note "; $edited = stristr($content, $query); $edited = preg_replace('~\b(' . preg_quote($query, '~') . ')\b~i', '<span class="found">$1</span>', $edited); echo truncate($edited, 32, 160);
Output for 4.3.0 - 7.1.0
<span class="found">Google</span> Glass Photographer by gogrovo 607,503 views | 4 days ago 1:30 Watch: A car that runs on your tweets and Facebook likes by ibnlive 301 views | 13 hours ago...