lcyew 0 Newbie Poster 15 Years Ago Hi there. Is there any way that can count the number of slashes in a string? For example: abs/frg/grgr/rgr/ and,the number of slashes can be obtained? Thanks for any solutions provided. php 0 0 Share network18 15 Practically a Master Poster 15 Years Ago This will give you the number of slashes in the string $str - Copy to Clipboard$str = "sdfsd/frg/grgr/rgr/"; $arr = explode('/',$str); echo $slashCount = count($arr) -1; 0 0 Share somedude3488 228 Nearly a Posting Virtuoso 15 Years Ago or use substr_count() 0 0 Share network18 15 Practically a Master Poster 15 Years Ago yes as kkeith29 says substr_count() is the better choice. it can like below - Copy to Clipboard$text = "sd/sdasd/dsda/"; echo substr_count($text, '/'); It will be faster than explode() 0 0 Share lcyew 0 Newbie Poster 15 Years Ago It's working!!! Thanks a lot....^^ 0 0 Share Share Facebook Twitter LinkedIn Reply to this topic Be a part of the DaniWeb community We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge. Sign Up — It's Free!
network18 15 Practically a Master Poster 15 Years Ago This will give you the number of slashes in the string $str - Copy to Clipboard$str = "sdfsd/frg/grgr/rgr/"; $arr = explode('/',$str); echo $slashCount = count($arr) -1; 0 0 Share
network18 15 Practically a Master Poster 15 Years Ago yes as kkeith29 says substr_count() is the better choice. it can like below - Copy to Clipboard$text = "sd/sdasd/dsda/"; echo substr_count($text, '/'); It will be faster than explode() 0 0 Share