earunder Posted May 21, 2009 Share Posted May 21, 2009 Oki, Here is what I'm trying to do.... I've set the variable, $model, from an xml sheet and would like to alter the variable to match the value from a database. For example... $model will equal the xml value of "ASTRA CDTI LIFE" sometimes model will equal "ASTRA ELITE" sometimes model will equal "VECTRA CLUB" and so on... Now I need to remove everything after the model as that in turn is the vehicle specifications... IE i want it to have a value of Vectra, Astra etc I hope that's easy to understand?? If not ask away and I shall try my best to explain better... so far I have... $model=str_replace("ASTRA", "Astra", $model); $model=str_replace("VECTRA", "Vectra", $model); I have also tried... $model=str_replace("%ASTRA%", "Astra", $model); $model=str_replace("%VECTRA%", "Vectra", $model); Any ideas ?? Many Thanks in advance Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 21, 2009 Share Posted May 21, 2009 $model = reset(explode(' ', $model)); Something like that? Quote Link to comment Share on other sites More sharing options...
earunder Posted May 21, 2009 Author Share Posted May 21, 2009 thats the one!!!!! Your a diamond! Thank your ever so much Quote Link to comment Share on other sites More sharing options...
Jibberish Posted May 21, 2009 Share Posted May 21, 2009 if the the model is always one word you could aways find the index of the 1st space and get a substring of it. <?php $model = 'ASTRA CDTI LIFE'; $model = substr($model, 0, strpos($model, ' ')); $model = str_replace("ASTRA", "Astra", $model); echo $model; ?> would print out 'Astra' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.