sierradog70 Posted March 2, 2007 Share Posted March 2, 2007 Hey, I have a form I am making for my site. Lets say the form is on page1.php. The user enters a domain on that form (ex domain-777.com) It sends all this to page2.php Now on page2.php I want the script to find out how many hiphens and numbers the entry has. I want it to know they entered 1 hiphen and 3 numbers. I believe I do this with the strstr function, but I am not sure. Even if I do, I don't know exactly how to do it. Please help Thanks! -Matt Link to comment https://forums.phpfreaks.com/topic/40810-a-little-help-with-processing-a-string/ Share on other sites More sharing options...
btherl Posted March 2, 2007 Share Posted March 2, 2007 There's a function specifically for that: http://sg.php.net/manual/en/function.count-chars.php Link to comment https://forums.phpfreaks.com/topic/40810-a-little-help-with-processing-a-string/#findComment-197585 Share on other sites More sharing options...
sierradog70 Posted March 2, 2007 Author Share Posted March 2, 2007 On that page, it has ($data, 1) <-- what does the 1 do? Also, what does the variable $i go to? Link to comment https://forums.phpfreaks.com/topic/40810-a-little-help-with-processing-a-string/#findComment-197587 Share on other sites More sharing options...
btherl Posted March 2, 2007 Share Posted March 2, 2007 The 1 selects the mode the function runs in. There's a list on that page near the top. The $i variable is the key.. the array returned looks like this: array( 'c' => 5, '.' => 1, '-' => 3, ); That foreach loop sets $i to be the "key" or "index", which is the character, and $val to be the "value", which is the number of times character $i appears in the string. Try the example script with a few input strings to get an idea of what's going on. Link to comment https://forums.phpfreaks.com/topic/40810-a-little-help-with-processing-a-string/#findComment-197592 Share on other sites More sharing options...
sierradog70 Posted March 2, 2007 Author Share Posted March 2, 2007 Got it, thanks! Link to comment https://forums.phpfreaks.com/topic/40810-a-little-help-with-processing-a-string/#findComment-197597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.