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 Link to comment https://forums.phpfreaks.com/topic/159081-need-some-help-using-str_replace/ Share on other sites More sharing options...
jackpf Posted May 21, 2009 Share Posted May 21, 2009 $model = reset(explode(' ', $model)); Something like that? Link to comment https://forums.phpfreaks.com/topic/159081-need-some-help-using-str_replace/#findComment-838932 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 Link to comment https://forums.phpfreaks.com/topic/159081-need-some-help-using-str_replace/#findComment-838934 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' Link to comment https://forums.phpfreaks.com/topic/159081-need-some-help-using-str_replace/#findComment-838937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.