The use of the $HTML variable is very constraining.
I had to convert an old php script which write HTML code.
In the old version, I used many
?> html code <?php and
echo to insert HTML code.
PHP Code:
<?php
// some code
// write HTML :
?>
<script type="text/javascript">
//<![CDATA[
var myVar1 = <?php if (isset($myPhpVar1)) { echo $myPhpVar1; } else { echo $myPhpVar1Default; } ?>;
var myVar2 = <?php if (isset($myPhpVar2)) { echo $myPhpVar2; } else { echo $myPhpVar2Default; } ?>;
var lenght = 25;
function func(){
if (lenght><?php echo $lenghtPHP; ?>)
{
document.getElementById('myID').value = document.getElementById('myID').value.substring(0,<?php echo $lenghtPHP; ?>);
}
}
//]]>
</script>
<?php
Now I had to write this :
PHP Code:
<?php
$HTML .= "
<script type=\"text/javascript\">
//<![CDATA[
";
if (isset($myPhpVar1)) {
$HTML .= "var myVar1 = ".$myPhpVar1.";";
else
$HTML .= "var myVar1 = ".$myPhpVar1Default.";";
if (isset($myPhpVar2)) {
$HTML .= "var myVar2 = ".$myPhpVar2.";";
else
$HTML .= "var myVar2 = ".$myPhpVar2Default.";";
$HTML .= "
var lenght = 25;
function func(){
if (lenght>".$lenghtPHP.")
{
document.getElementById('myID').value = document.getElementById('myID').value.substring(0,".$lenghtPHP.");
}
}
//]]>
</script>
";
?>
The new version is very hard to read :erm:
Do you know an easier way to convert this script?
For example, is it possible to insert PHP condition into concatenation?
PHP Code:
<?php
$HTML .= "
<script type=\"text/javascript\">
//<![CDATA[
var myVar1 = ". /* PHP condition before concatenation */ ."
var myVar2 = ". /* PHP condition before concatenation */ ."
var lenght = 25;
function func(){
if (lenght>".$lenghtPHP;")
{
document.getElementById('myID').value = document.getElementById('myID').value.substring(0,".$lenghtPHP.");
}
}
//]]>
</script>
";
?>