[SOLVED] Variable inside string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Variable inside string

Post by dwfait »

would this work?

"news/$id.txt"

or would it come out as news/$id.txt?
If it does, how would i put the variable $id inside the string?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

<?php
$id="hello";
$a="news/$id.txt";
$b='news/$id.txt';
echo $id.'<br>'.$a.'<br>'.$b.'<br>';
?>
Returns :
hello
news/hello.txt
news/$id.txt
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

thanks :)
Post Reply