Jump to content

[SOLVED] String question


Minase

Recommended Posts

Constants don't magically interpolate into strings.  You'll either need to use a variable or concatenate.

 

<?php
$test = "a value ...";
$text = "Welcome to $test ,enjoy your stay"; //notice the DOUBLE QUOTES
?>

<?php
define("test", "a value ...");
$text = 'Welcome to ' . test . ' ,enjoy your stay.';
?>

hy there ,i have the following code

 

define ("test", "a value ...");
$text = 'Welcome to test ,enjoy your stay';

// the output should be $text = 'Welcome to a value... , enjoy your stay';

 

i tryed eval but doesnt work ...

thank you

it sets a named constant. the only way you can use that so it works would be something like

<?php
define ("TEST", "a value ...");
$text = "Welcome to ".TEST." ,enjoy your stay";
print $text;
?>

now, to replace, I would use

<?php
$text = "Welcome to test ,enjoy your stay";
$text = str_ireplace("test", "a value....", $text);
print $text;
?>

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.