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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.