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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
sierradog70 Posted March 2, 2007 Author Share Posted March 2, 2007 Got it, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.