HowdeeDoodee Posted June 17, 2007 Share Posted June 17, 2007 I need to combine the variable values shown below into a regular expression $composite with a separator of | Any help would be appreciated. Here is an example. $A = "shoe"; $B = "box"; $C = "wrapper"; $termcrm = "crm"; $sep = "|"; $composite = 'shoe|box|wrapper|crm'; Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/ Share on other sites More sharing options...
chigley Posted June 17, 2007 Share Posted June 17, 2007 <?php $array = array("shoe", "box", "wrapper", "crm"); $sep = "|"; $composite = join($sep, $array); ?> Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/#findComment-276447 Share on other sites More sharing options...
GingerRobot Posted June 17, 2007 Share Posted June 17, 2007 Well, unless you can put those variables into an array, or unless the variable names follow a pattern, then your only choice is going to be: $composite = $var1.'|'.$var2.'|'.$var3.'|'.$var4;//etc Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/#findComment-276448 Share on other sites More sharing options...
HowdeeDoodee Posted June 17, 2007 Author Share Posted June 17, 2007 OK, gingerrobot thank you for the response. When I tried your suggestion, I got this error message: Parse error: syntax error, unexpected T_VARIABLE The code used was: <?php $A = 'Hello'; $B = 'World'; $C = 'Beautiful'; $D = 'Day!' $composite = $A .'|' . $B . '|' . $C . '|' . $D;// echo $composite; ?> To chigley... Thank you for the suggestion. The values come into a script. I need to convert the values from $variables but not by hand as you show in your example. Thank both of you again. Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/#findComment-276457 Share on other sites More sharing options...
GingerRobot Posted June 17, 2007 Share Posted June 17, 2007 You're missing the semi colon at the end of the line before: <?php $A = 'Hello'; $B = 'World'; $C = 'Beautiful'; $D = 'Day!'; $composite = $A .'|' . $B . '|' . $C . '|' . $D;// echo $composite; ?> Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/#findComment-276466 Share on other sites More sharing options...
HowdeeDoodee Posted June 17, 2007 Author Share Posted June 17, 2007 GingerRobot, I have a red face but am very happy. You are correct both in regard to syntax and my omission. Your solution works. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/55969-solved-convert-separate-string-variables-to-simple-regular-expression-element/#findComment-276480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.