sam sam - 4 months ago 8
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
\common\models\ShoeBrand
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
<?php

$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 \\.