Hello,

Somehow this is not working. I tried pretty much everything.
I am also very new to PHP, but i made a nice CMS. Now I am making a website with some random flash-videos every time you refresh. This is what i got so far:

<html>
<head>
<title>Sydcul.com</title>
</head>
<body>
<h1>Sydcul.com</h1>
<h2>Warning: flashing images!</h2>
<p>It would be fun to turn on your sound.</p>
<?php
echo('This is visible, all stuff below is not. So the closing tags are not visible too.');
echo('<embed src="flash/' . rand(1, 5) . '.swf" type="application/x-shockwave-flash" width="320" height="240></embed>');
?>
</body>
</html>

I am not really sure how to implement HTML in PHP, so it is something really small i guess.

Dani AI

Generated

A concise diagnosis and safe patterns. The behavior reported by — an initial PHP echo showing but the rest of the page disappearing — is classic evidence of a quoting/parse problem inside an echoed HTML string (as identified). Both switching quote styles (noted by ) and breaking out of PHP to write plain HTML (as and suggested) are valid ways to avoid that class of mistake, but a more robust approach is recommended for production code.

Quick, practical checks:

  • Enable development error reporting to see PHP parse/errors immediately.
  • Inspect browser “View Source” to confirm what HTML was emitted.
  • Avoid short PHP tags (<?) unless short_open_tag is known to be enabled; use <?php to be safe.
  • Confirm file existence and permissions for any media files referenced.

Enable error reporting (development only):

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

A safer pattern for selecting and outputting a random media file is to build the list and chosen filename in PHP, sanitize it, then emit plain HTML. The example below uses glob() and array_rand() to pick a file and htmlspecialchars() to prevent attribute injection:

<?php
$files = glob(__DIR__ . '/flash/*.swf');
if (!empty($files)) {
    $pick = $files[array_rand($files)];
    $src  = 'flash/' . basename($pick);            // whitelist by using basename()
    $safe = htmlspecialchars($src, ENT_QUOTES, 'UTF-8');
}
?>
<embed src="<?php echo $safe; ?>" type="application/x-shockwave-flash" width="320" height="240"></embed>

Longer-term notes: Flash is deprecated and unsupported in modern browsers; prefer converting content to MP4 and using the HTML5 <video> element. Keep logic (file selection, validation) in PHP and output minimal HTML to avoid quoting errors, and always sanitize/whitelist filenames before exposing them to users.

Recommended Answers

All 4 Replies

Try with double quotes, use statement given below, Php string is in double quote and html element values are in single quote

echo("<embed src='flash/" . rand(1, 5) . ".swf' type='application/x-shockwave-flash' width='320' height='240'></embed>");

You have done it OK, only a double quote (as part of html attribute value) is missing after 240.

echo('<embed src="flash/' . rand(1, 5) . '.swf" type="application/x-shockwave-flash" width="320" height="240"></embed>');

why don't you try like this (replace your php code with bellow code it works perfectly)

<?php

echo('This is visible, all stuff below is not. So the closing tags are not visible too.');

?>
<embed src="flash/<? echo rand(1, 5);?>.swf" type="application/x-shockwave-flash" width="320" height="240"></embed>


<?
  // remaining your code 
?>

Going to explain the above post more.

basically all your doing is stopping your php, doing html and re-entering php. PHP like many languages has the ability to jump in and out using tags

<?php echo'//Functionhere' ?>

As long as you open and close properly it's fine. You can also echo HTML :)

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.