Jump to content

[SOLVED] Convert separate string variables to simple regular expression element


HowdeeDoodee

Recommended Posts

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'; 

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

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.

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;
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.