Page 1 of 1
string issue
Posted: Mon Jan 23, 2006 10:17 am
by itsmani1
there is a tring
$str = " Abc Def";
want to fetch Abc only, is there any php function that can help me, i want to fetch string before " "
thanx
Posted: Mon Jan 23, 2006 10:26 am
by JayBird
Is the first space in the string intentional (you have two)?
If not
Code: Select all
$str = "Abc Def";
$parts = explode(" ", $str);
echo $parts[0];
// outputs Abc
Posted: Mon Jan 23, 2006 10:27 am
by jasonjohnson
If you know how long that segment is going to be, you can use
substr() -- or, if you know you will always have whitespace surrounding your segments per your example, you can use
explode().
For instance:
Code: Select all
$str = " Abc Def";
echo substr($str, 1, 3);
Where
$str is obviously the variable you're slicing up,
1 is the starting point, and
3 is the number of characters you expect to pull out of the string from the starting point forward.
Posted: Mon Jan 23, 2006 11:26 am
by itsmani1
Code: Select all
mysql_query("select ContactID, FirstName, EmailAddress from Contacts where ContactID IN(select ContactID from TenantLocationsContacts where TenantLocationsID IN (select TenantLocationsID from TenantLocationsContacts where TenantLocationsID IN (select TenantLocationsID from TenantLocations where TenantID=1) GROUP BY TenantLocationsID HAVING count(TenantLocationsID) > 1))") or die("");
there is some issue with this? can any one help me?
Posted: Mon Jan 23, 2006 11:32 am
by Chris Corbyn
itsmani1 wrote:Code: Select all
mysql_query("select ContactID, FirstName, EmailAddress from Contacts where ContactID IN(select ContactID from TenantLocationsContacts where TenantLocationsID IN (select TenantLocationsID from TenantLocationsContacts where TenantLocationsID IN (select TenantLocationsID from TenantLocations where TenantID=1) GROUP BY TenantLocationsID HAVING count(TenantLocationsID) > 1))") or die("");
there is some issue with this? can any one help me?

What did this have to do with the original post?
Change or die('') to `or die(mysql_error())'.
As to the first post you may want to look at regular expressions if the other two posters' comments haven't helped
