I am trying to get into some PHP and I can't seem to figure out the following.
I can create a string by means of PHP with concatenation:
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
But what if you want to do this with a variable? (I am guessing WP's functions can be called variables.) I am quite lost here. The following does not work. Or at least, my text editor throws an unknown error.
<?php
if ( is_404() ) {
echo "<script src='" . get_stylesheet_directory_uri(); . "/sm/script/soundmanager2-nodebug-jsmin.js'></script>
<script>
soundManager.setup({
url: '" . get_stylesheet_directory_uri(); . "/sm/swf/',
onready: function() {
var mySound = soundManager.createSound({
id: 'aSound',
url: 'http://www.mysite.com/sound.mp3',
volume: '25'
});
mySound.play();
},
ontimeout: function() {
}
});
</script>"
}
?>
You can also change your approach to avoid such problems. Instead of embeding HTML into PHP you can embed PHP into HTML closing and opening PHP tags:
You can save yourself a lot of headache if you simply save the return value of the function:
Try this
you are adding ; in between the code which is incorrect.
It goes wrong here:
You have a
;
in the middle of your sentence. Also at the end of your string you don't have a;
Correct syntax
Try this: