-1
  1. I have .txt file, namely "104.txt", and I save in my hosting like this: http://example.com/files/104.txt

  2. I have post with ID Post: 104

If I use this code to show txt file in my theme, it's fine work:

<?php
echo file_get_contents( "http://example.com/files/104.txt" );
?>

But, If I use Post ID for name file, it don't work:

<?php
$id = get_the_ID();
echo file_get_contents( "http://example.com/files/'.$id.'.txt" );
?>

MY QUESTION: How to resolve to show txt file in PHP with ID Post for name file? Thanks

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
PUSTAKAKORAN.COM
  • 455
  • 1
  • 5
  • 18

1 Answers1

1

You can do it like below:-

echo file_get_contents( "http://example.com/files/$id.txt" );

OR

echo file_get_contents( "http://example.com/files/$id".".txt" );

OR

echo file_get_contents( "http://example.com/files/".$id.".txt" );

Note:-

Reference:- What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98