0

Hi all.

I have the following problem:
I read this string from an XML file: "User Name ={$username}"
and then store it in a local variable $test.

I read this in a function, where I have a local variable $username.

However the variable inside the string is not interpreted to get the local value, but just seen as a string itself.

so if i do: echo $test I get "User Name ={$username}".

if I define this locally as $test2="User Name ={$username}", the $username is interpreted correctly.

Any help will be greatly appreciated.
Thanks
Aristos

2
Contributors
7
Replies
9
Views
8 Years
Discussion Span
Last Post by aristos32
0

could you show ur code?

function sendAutomatedEmail($username)
{
//$username=c
...
foreach($_SESSION['emailMessagesArray'] as $generalType)
	{
		if($generalType->name==$EMAIL_MESSAGE_NEW_USER_CREATED)
		{
			$subject=$generalType->description;
			$subject2="User Name ={$username}\n";
			//$message="$generalType->value";
			break;
		}
			
	}
...
}//end of function

$_SESSION['emailMessagesArray'] is an array of structures read from the xml.

$generalType->description is taken from XML tag: <description>User Name ={$username}</description>

When i do:

echo "SUBJECT2=$subject2";
echo "SUBJECT1=$subject";

it prints :
SUBJECT2=User Name =c SUBJECT1=User Name ={$username}

0

$subject2="User Name ={$username}\n";

in this line its taking as "User Name ={$username}\n" a string and printing is as it is like a string becuase in php Double quotes use for strings. any thing in double quotes will not performs any check or action but just print the characters in it.

$subject=$generalType->description;

0

what about: $subject2="User Name ={$username}\n"; this is also a string in double quotes, but php interprets it correctly.

0

well i just tried your code and its new to me that if the php variable is with in double quotes it still works

0

well i just tried your code and its new to me that if the php variable is with in double quotes it still works

yes, i found this also trying to solve this problem and it seems quite useful for my work.

i think it should be a way for the first string to work as well, since defining it locally works fine...

thanks for your reply.

0

After 2 years I came back to the same problem again. Any help will be appreciated!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.