0

I am trying to write a string to a newly created file but when I write it to my newly create file I see the value of the string, but what I want actually is the string to show like $id = 15; but I only see 15 please someone should help me out I have been on this for hours

if (file_exists($file)) {
    $newfile = "../".$low.$row["page_id"].".php";
    $url = "../".$low.$row["page_id"];
    $create = fopen($newfile,"w");

    $addfile = "<?php  include '../page.php'; ?>";
    $write = fwrite($create, $addfile);
    fwrite( $create, "<?php $id = $pid; ?>" );
}

what I want is to see $id = $pid inside the newly created file but instead, I see the value it store

Bablu Ahmed
  • 4,412
  • 5
  • 49
  • 64
alertme
  • 61
  • 7

1 Answers1

-1

Try replace:

From:

fwrite( $create, "<?php $id = $pid; ?>" );

To:

fwrite( $create, '<?php $id = '. $pid .'; ?>' );

PHP strings can be specified in several ways - see this link stackoverflow.com/a/3446286/4111622 .

Double quotes strings with variables inside will use the variable $name value into the string result.

$name = "cale_b"; 
echo( "My name is $name" ); 
output: "My name is cale_b" 

Single quote will not replace it.

echo( 'My name is $name' ); 
output: "My name is $name"
Valdek Santana
  • 337
  • 1
  • 8
  • Hi @cale_b, PHP strings can be specified in several ways - see this link https://stackoverflow.com/a/3446286/4111622 . Double quotes strings will replace the variable $name value to the string result. $name = "cale_b"; echo( "My name is $name" ); output: "My name is cale_b" Single quote won.'t echo( 'My name is $name' ); output: "My name is $name" – Valdek Santana May 03 '18 at 18:36
  • 1
    this already solve my problem thanks alot – alertme May 03 '18 at 18:43
  • I added the reference to my answer. If it worked for you guys please vote accordingly. Thank you. – Valdek Santana May 03 '18 at 19:02
  • @alertme could you mark it as the answer once it solved your problem? – Valdek Santana Nov 12 '18 at 16:32
  • @cale_b I explained your doubt editing the answer and it resolved the alertme question. Please let me know if you need anything else. Thank you guys. – Valdek Santana Nov 12 '18 at 16:32