Jump to content

A little help with processing a string


sierradog70

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.