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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.