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

could you show ur code?

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}

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

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

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.