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
string issue
Moderator: General Moderators
Is the first space in the string intentional (you have two)?
If not
If not
Code: Select all
$str = "Abc Def";
$parts = explode(" ", $str);
echo $parts[0];
// outputs Abc
Last edited by JayBird on Mon Jan 23, 2006 10:36 am, edited 1 time in total.
- jasonjohnson
- Forum Newbie
- Posts: 6
- Joined: Wed Jan 18, 2006 9:21 am
- Location: Dallas, TX, USA
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:
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.
For instance:
Code: Select all
$str = " Abc Def";
echo substr($str, 1, 3);- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
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("");- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
itsmani1 wrote:there is some issue with this? can any one help me?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("");
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