947740 Posted October 14, 2008 Share Posted October 14, 2008 I want to see if a certain string starts with 192., and if it does not, add it to a total. The syntax is slipping my mind right now... Link to comment https://forums.phpfreaks.com/topic/128413-string-search/ Share on other sites More sharing options...
Orio Posted October 14, 2008 Share Posted October 14, 2008 Can't understand what's "add it to a total", but here's the syntax you're looking for: <?php if(strpos($str, "192.") === 0) { //It starts with "192." } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665355 Share on other sites More sharing options...
947740 Posted October 14, 2008 Author Share Posted October 14, 2008 I just meant add the total number of strings that do not start with 192. Thank you. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665358 Share on other sites More sharing options...
Orio Posted October 14, 2008 Share Posted October 14, 2008 I still don't get what source of strings you're talking about. Anyway, can't you get it done from here? Orio. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665362 Share on other sites More sharing options...
947740 Posted October 14, 2008 Author Share Posted October 14, 2008 Just to explain, I have a whole bunch of different strings. I want to find the total number of strings that do not start with "192.". Yes, I can continue from here. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665365 Share on other sites More sharing options...
Orio Posted October 14, 2008 Share Posted October 14, 2008 Let's say they were in the array $numbers: <?php $counter = 0; foreach($numbers as $str) if(strpos($str, "192.") !== 0) $counter++; echo $counter; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665376 Share on other sites More sharing options...
947740 Posted October 14, 2008 Author Share Posted October 14, 2008 Thank you. Link to comment https://forums.phpfreaks.com/topic/128413-string-search/#findComment-665380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.