jerastraub Posted October 6, 2006 Share Posted October 6, 2006 Hello,I have a question. Is there a way to split a string into several strings. Like:offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25'' long. Sizes: M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W).I want to split this string into 2 stringsFirst one would be:offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25'' long.second would be:Sizes: M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W).And then display them in an echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/ Share on other sites More sharing options...
effigy Posted October 6, 2006 Share Posted October 6, 2006 [code]<pre><?php $string = "offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25'' long. Sizes: M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W)."; $pieces = preg_split('/(?=Sizes)/', $string); print_r($pieces); ?></pre>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105149 Share on other sites More sharing options...
.josh Posted October 6, 2006 Share Posted October 6, 2006 here's my ghetto solution:[code]$oldstring = "offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25'' long. Sizes: M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W).";$d = 'Sizes:';$strings = explode($d, $oldstring);$strings[1] = $d . $strings[1];echo "1st part: $strings[0] <br>";echo "2nd part: $strings[1]";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105151 Share on other sites More sharing options...
kenrbnsn Posted October 6, 2006 Share Posted October 6, 2006 Here's yet another way (YAW):[code]<?php$str = 'offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy ' . 'side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25" long. Sizes: ' . 'M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W)';$sp = strpos($str,'Size');$str1 = substr($str,0,$sp);$str2 = str_replace($str1,'',$str);echo 'String : ' . $str . "<br><br>\n";echo 'String 1: ' . $str1 . "<br><br>\n";echo 'String 2: ' . $str2 . "\n";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105175 Share on other sites More sharing options...
jerastraub Posted October 6, 2006 Author Share Posted October 6, 2006 Nope not working :(Here my code:[code]<?include("config.php");// Get All Product Information Below For SE Optimizing$sql = "SELECT ProductName,BriefDesc,prodPrice,IntermDesc,ProductURL,BigImage,PermuColor,prodSale,CategoryID,Category FROM womensproducts WHERE ProductID = '$pid' ";$query = mysql_query($sql);$viewproduct = mysql_fetch_array($query);$active = mysql_num_rows(mysql_query($sql)); $oldstring = $viewproduct[3];$d = 'sizes';$strings = explode($d, $oldstring);$strings[1] = $d . $strings[1];$lowercolors = strtolower($viewproduct[6]);$colors = ucwords($lowercolors);$colors = ucwords($lowercolors);?>[/code][code] <td class="quick" align=center><? echo $strings[0]; ?><br><br><? echo $viewproduct[3]; ?><br><br> Avail. $strings[1] <br><br> <br>Avail. Colors: <? echo $colors; ?>[/code]Am i missing something? Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105179 Share on other sites More sharing options...
kenrbnsn Posted October 6, 2006 Share Posted October 6, 2006 Case of the string being searched for?[code]<?php $d = 'sizes'; ?>[/code]In your original message you had 'Sizes'Ken Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105186 Share on other sites More sharing options...
jerastraub Posted October 6, 2006 Author Share Posted October 6, 2006 Okay, Here's another one for ya:The wording be the size can beSizeor Full and half sizes.How do it get it do this.I know I have to perform a test, but having trouble figuring it out! Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105197 Share on other sites More sharing options...
Barand Posted October 6, 2006 Share Posted October 6, 2006 try[code]<?php$s1 = 'Full and half sizes:';$s2 = 'Sizes:';$str = "offers cozy texture and a comfy full fit. Pleated at yoke for a cape-like sweep. Ribbed texture on the yoke and cuffs. Handy side-seam pockets. Full sleeves gathered at cuffs. Woven cotton/polyester. Machine wash. Imported. 25'' long. Full and half sizes: M(14W-16W), L(18W-20W), 1X(22W-24W), 2X(26W-28W), 3X(30W-32W), 4X(34W-36W).";$split = (($p=strpos($str, $s1))===false) ? strpos($str,$s2) : $p;$t1 = substr($str,0,$split);$t2 = substr($str,$split);echo '<p>' . $t1 . '</p><p>' . $t2 . '</p>';?>[/code]Edited to include ":" in search strings suggested by mjdamato below Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105205 Share on other sites More sharing options...
Psycho Posted October 6, 2006 Share Posted October 6, 2006 An even better solution would be to split the description and size information text into separate fileds within the database. At the very least you should do a check of your data to ensure that "Size" or "Full and half sizes" occurs at least once where appropriate and doesn't appear in the description - I could see where "Size" might be int eh description, so I would add the colon as part of the search value. Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105209 Share on other sites More sharing options...
jerastraub Posted October 6, 2006 Author Share Posted October 6, 2006 I wish creating field in my database for this wouldn't be a very time consuming idea, as I use 12 datafeed on just this one site. These datafeeds are updated daily, so I upload them daily. If you compound that by 33 site in different nich markets. All my time would be spent modifying feeds rather than seo and customers service. Quote Link to comment https://forums.phpfreaks.com/topic/23192-splitting-a-string-into-several-strings/#findComment-105250 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.