Syntax error, unexpected; expecting)

-1

I have the problem with the following PHP code:

$urlcontent = '
<?php
$servername = ".'$servername'.";
$mcpelist = ".'$mcpelist'.";
$longlink = ".'$longlink'.";
$alias = ".'$alias'.";
include ("../configs/variables.php");
include ("../configs/template.php");
?>';

@AngelFragaParodi or who can help me ...

I changed it to

 // Content of every shortened URL
    $urlcontent = '<?php
    $servername =  "'.$servername.'";
    $mcpelist =  "'.$mcpelist.'"
    $longlink =  "'.$longlink.'"
    $alias =  "'.$alias.'"
    include ('../configs/variables.php');
    include ('../configs/template.php');
    ?>';

and it does not work.

    
asked by Josue Federico 08.04.2017 в 21:21
source

2 answers

1

Good Josue, the problem is the concatenation of your chains with PHP variables. That is, to concatenate variables in PHP the point is used.

To achieve this correctly you must open and close the quotation marks correctly at all times.

One note to keep in mind is that in PHP the use of double quotes allows the use of PHP variables inside without having to open and close the quotes and use the period.

In your case you start using single quotes, which you need to close and open again to concatenate. An example of what you have done is:

 $miVariable = '<?php  $servername = ".'$servername'."; ?>';

This would be wrong, being the right way:

 $miVariable = '<?php  $servername = "'.$servername.'"; ?>';

Changing the place of the points can be concatenated correctly.

UPDATE

Josue, when you use quotes again in the include, you close the concatenated string again, exactly here:

include ('../configs/variables.php');
include ('../configs/template.php');

Change this part for this:

include ("../configs/variables.php");
include ("../configs/template.php");

I recommend using a code editor with syntax highlighting to indicate these errors visually and you can correct them at the same time.

An example of what happened to you is:

 <?php 
   $miEdad = 10 ;
   $miFrase = "Tengo ";
   $finalComillasDobles = $miFrase." $miEdad años";
   echo $finalComillasDobles;
   $finalComillasSimples = $miFrase.' '.$miEdad.' años';
   echo $finalComillasSimples ;
   $finalComplejo ="Hola amigo. '$miFrase $miEdad años'.".'Hasta luego ';
   echo $finalComplejo ;
?>

This example would give an output of:

"Tengo 10 años"
"Tengo 10 años"
"Hola amigo. 'Tengo 10 años'.Hasta luego "

In short, the use of single and double quotes is indifferent with the only difference that doubles allow us to use our variables without concatenating, if we use both we only have to know when to close and open each one.

    
answered by 08.04.2017 в 21:29
0

You have to escape the quotes of the includes. Enter \' instead of ' .

But I would recommend that you change the design of the program to not generate the PHP code yourself. Use some template engine of the many that exist.

    
answered by 08.04.2017 в 23:54