emexinc Posted January 4, 2009 Share Posted January 4, 2009 ...this is my problem... <?php $size = "2 3/16 x 4 1/2"; $size = str_replace("x", "" x", "$size"); echo $size."""; ?> or <?php $size = "2 3/16 x 4 1/2"; $size = str_replace("x", "" x", "$size"); echo $size."""; ?> ...and this echoes 2 3/16 " x 4 1/2"...but i am trying to get 2 3/16" x 4 1/2"...i have tried this code below... <?php $size = "2 3/16 x 4 1/2"; $size = str_replace(" x", "" x", "$size"); echo $size."""; ?> or <?php $size = "2 3/16 x 4 1/2"; $size = str_replace(" x", "" x", "$size"); echo $size."""; ?> ...and this echoes 2 3/16 x 4 1/2"...but i am assuming that it didn't find anything to replace... ...but then it can't find the x with a space in front of it...the challenging part of this code is the dimensions are changing ( 4" - 4 1/2" - 4 1/16" )...that's why i am looking for an x...and trying to add the quote, and then easily adding a quote at the end...how do i go about getting this work, and possibly getting this to work easier than i have it set up?...thanks ...sorry, i have the code posted twice to show that the code function in this forum is changing " to &#34; Link to comment https://forums.phpfreaks.com/topic/139439-solved-str_replace/ Share on other sites More sharing options...
kenrbnsn Posted January 4, 2009 Share Posted January 4, 2009 How about something like this: <?php $size = "2 3/16 x 4 1/2"; list($p1,$p2) = explode(' x ',$size); echo $p1 . '" x ' . $p2 . '"'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/139439-solved-str_replace/#findComment-729389 Share on other sites More sharing options...
emexinc Posted January 4, 2009 Author Share Posted January 4, 2009 ...what if i have a dimension where three sizes are given, even though most will be two?...is there a way for me to use this method and add an if statement to check, or is there an easier way?...thanks for the quick response Ken... Link to comment https://forums.phpfreaks.com/topic/139439-solved-str_replace/#findComment-729398 Share on other sites More sharing options...
kenrbnsn Posted January 4, 2009 Share Posted January 4, 2009 Generalized: <?php $size = "4 1/2 x 5 x 1 3/4"; $new_size = implode('" x ',explode(' x ',$size)) . '"'; echo $new_size . '<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/139439-solved-str_replace/#findComment-729411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.