sam sam - 1 year ago 57
PHP Question

How to concatenate and string and escapte characters in php

I'm having problem concatenating and escaping string i have this in my code

$specModel = 'ShoeBrand';
$modelName = "\common\models\".$specModel ;

i would like to produce somethinglike
and it's not working below are all my try and the output

"\common\models\'".$specificsModel; output '\common\models\'ShoeBrand'
$modelName = "\common\model".'\'.$specificsModel;

all not working any help on this thanks

Answer Source

$specModel = "ShoeBrand";
$modelName = "\\common\\models\\" . $specModel;

echo $modelName;
// will echo \common\models\ShoeBrand    

You need to escape the backslash with a backslash. Same as you would to escape a ' you would do \'. Here you have to do \\.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download