PDA

View Full Version : PHP - How to replace a particular word in a string variable


cinq
02-09-2004, 02:41 PM
Say i have a variable called $booktitle which is a string containing titles of children's story books.

In this string, i can have values like

'Instock - The Lord of the Rings'
'Instock - The Lord of the Rings vol.2'
and so on.

However i want to print the variable without the instock wording.
Hence how can i replace it such that when printing out the list, it would ignore the instock wording and in its place put 'It's available in stores!' instead ?

Dean C
02-09-2004, 02:46 PM
$string = str_replace('InStock', '', $string);

cinq
02-09-2004, 02:50 PM
Fantastic Dean, works fine.
Once again, thanks a million :D

Dean C
02-09-2004, 05:30 PM
No problem :)