Link to home
Create AccountLog in
Avatar of twittoris
twittoris

asked on

character count until comma

Is there a way to make the '12' in $var2 equal to the end of an address?
For example.

COMPANY A 100 Avenue K, Suite 205 NEW YORK, NEW YORK, 10014

COMPANY A = strlen($row['ENTITY_M']) so thats taken off the address string
Can it detect how many characters there are up until th e first comma so that $var2 would = 100 Avenue K
//Find how many characters are in the first part of the address                                  
                                    echo "STRING LENGTH: ". strlen($row['ENTITY_M']);

//Create a searchable variable to match the underlying address
                          $var2 = substr($row['ENTITY_ADD'], strlen($row['ENTITY_M']), 12);
//Search database for something like the remainder of the address string
                          $query2 = "SELECT * FROM $tbl_name WHERE `ENTITY_ADD` LIKE '%".$var2."%'";
                          $result2 = mysql_query($query2) or die(mysql_error());

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Easy!  explode() on comma and get strlen of the first part of the array.

Or get strpos() of the comma.
All of the PHP functions are documented with user-contributed notes on the PHP web site.  Example:
http://us2.php.net/manual/en/function.strpos.php
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of twittoris
twittoris

ASKER

Please show code.
The code is at ID:34452172.

But the PHP man pages are a much better online learning resource than me.  I only know what I know.  The PHP community is smarter than any one individual.  That is why I recommend that you check the man pages on PHP.net every time you use a function.  When you know a function so well that you no longer need to check the man page, you have a proficiency in that function.  There are over 4,000 PHP functions, and they are all documented there on PHP.net.