I have an variable $query
which holds for example 5.6" display
or 5.6 " display
is there anyway to change it to 5.6 inch display
for both of the previous given examples? I tried using preg_split but I had no luck so far.
Asked
Active
Viewed 329 times
0

vincent kleine
- 724
- 1
- 6
- 22
-
You want to remove the quotation marks? – Enayet Hussain May 12 '15 at 20:33
-
Yes, and replace it with "inch" – vincent kleine May 12 '15 at 20:34
-
1`str_replace()` should work – Jay Blanchard May 12 '15 at 20:34
-
Is the variable guaranteed to only have the double quotes after a number? – Daryl Gill May 12 '15 at 20:35
1 Answers
2
You can use
str_replace('"', ' inch', $query);
To replace any quotation marks with " inch"
If you put in 5.6" it will output
5.6 inch
EDIT: If you want to remove double spaces of which would happen if you input
5.6 "
Then you should run this code after
preg_replace('/\s/', ' ', $query);

Enayet Hussain
- 908
- 4
- 17
- 33
-
1
-
1
-
-
1
-
Why don't you just provide your own answer? I've given a solution that will work but if you have a solution that works better then go ahead and share – Enayet Hussain May 12 '15 at 20:45
-
It's a learning curve for you also. OP is looking to replace a double quote after a number (could include a white space before and after) followed by a string – Daryl Gill May 12 '15 at 20:48
-
Yeah I know that's why I'm eager to hear your solution. I'm not here to disagree I'm here to learn :) – Enayet Hussain May 12 '15 at 20:51