We help IT Professionals succeed at work.
Get Started

character count until comma

twittoris asked
Last Modified: 2012-08-13
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

Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE