laravel - How do I remove texts after the second comma in php -


how can remove texts in sentence after second comma nothing if has no two commas in sentence?

i tried following:

substr($str, 0, strpos($str, ',', strpos($str, ',')+1)) 

but problem here if don't have 2 commas in $str, funtion outputs nothing, i'm getting blank area.

is there anyway check existence of 2 commas , remove text after second comma or nothing otherwise.

try this:

$commascount = count(explode(',', $str)); if ($commascount > 2) {     $str = substr($str, 0, strpos($str, ',', strpos($str, ',')+1)); } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -