//não exibe a imagem, por quê?
echo "<img src=". $num .">";
The result of this will be
<img src=criança com bolo.jpg>
HTML will interpret the end of the file in the first space character:
<img src=criança >
Obviously, since this name does not exist, it returns a non-existent image. Moreover, the directory must be defined. img/
In the version in which you wrote directly, you inserted the bounding quotes and directory:
//quando coloco o nome do arquivo direto funciona:
echo "<img src='img/criança com bolo.jpg'>";
This results in <img src='img/criança com bolo.jpg'>
Due to quotation marks, the HTML interpreter understands that you should read the file name up to the closing quote.
To resolve, add the bounding quotes and the correct path:
echo "<img src='img/". $num ."'>";
These are basic HTML rules. PHP itself has no relation. But it is common to confuse these mixtures with languages.
If you want to use double quotes in HTML, just invert, using single quotes in PHP:
echo '<img src="img/'.$num.'">';
*In PHP, it is recommended to use simple quotes to delimit the strings.
The double quotes have a specific purpose for the compiler, which consumes a little more resources (memory, processor, etc).
As for the use of Urlencode, it is unnecessary, because the browser itself does the conversion, except very old browsers of more than 10 years ago.
Practical example, access the following URL:
http://www.amazon.co.jp/タイムセール/b/ref=nav_topnav_deals?ie=UTF8&node=2221688051
It is a page of Amazon Japan. Note the katakana in the URL.
The purpose of the term in Japanese is for SEO.
Imagine if you use urlencode or rawurlencode, see how it would look:
http://www.amazon.co.jp/%E3%82%BF%E3%82%A4%E3%83%A0%E3%82%BB%E3%83%BC%E3%83%AB/b/ref=nav_topnav_deals?ie=UTF8&node=2221688051
Horrible.. spoiled the URL.. "spoiled the SEO" of this page.
In older browsers, from 2003 or 2004 onwards, multibyte characters will be automatically converted with their respective entities, this includes Latin characters.
As I mentioned in other discussions regarding encodes, the developer needs to have a globalized vision to build an internationalized platform. The vast majority of Velopers build localized systems and many think their systems are global and actually are not.
I avoided commenting here on this topic because I found it unnecessary and would distort the main focus of the question, but anyway, I hope I made it clear.
Good evening @Nilson, some of the answers solved your problem?
– Guilherme Nascimento
Good evening, I wonder if any of the answers helped you, if not please comment on what you think is missing.
– Guilherme Nascimento