• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

PHP Funktion in einer PHP echo Bedingung

the_zoker_09

Mitglied
Hallo zusammen,

Ich möchte eine php Funktion in einer Bedingung aufrufen:
PHP:
if ( $instance['status']=='print' ) {
     echo '<?php if(function_exists('stbHighlightText')) stbHighlightText('Der aktuelle <a href="'.$instance['post'].'">'.$instance['name'].'</a> befindet sich aktuell in Druck.', 'test'); ?>';}

Das Problem ist, das durch die ' in der php if(function_exists) das echo gestört wird und ich folgenden Fehler bekomme:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in status-widget.php on line 143

Wie kann ich das Problem lösen?

Vielen Dank
Zoker

PS: Ich hoffe man konnte mein Problem verstehen :)
 
Werbung:

Willst du das als Code anzeigen?

if ( $instance['status']=='print' ) {
echo '<?php if(function_exists(\'stbHighlightText\')) stbHighlightText(\'Der aktuelle <a href="'.$instance[\'post\'].\'">\'.$instance[\'name\'].\'</a> befindet sich aktuell in Druck.\', \'test\'); ?>';

}



Hoffentlich ist das richtig so...;)
 
Zuletzt bearbeitet:
Und wo kommt das echo hin?

Im Prinzip geht es darum, dass ich ein ' in einem ' Nutze, ohne dass PHP denkt, das zweite würde das erste beenden:
Code:
'Der Teil außen 'hier ist der teil innen' und hier wieder außen'
in php:
PHP:
if ( $example['irgendwas']=='test' ) {
echo '<php irgeindeinefunktion( 'Hier kommt text '.$example['wasanderes'].' Und hier auch wieder Text' ); ?>';
}
 
Zuletzt bearbeitet:
Werbung:
Werbung:
Das Problem ist, dass die <?php Funktion im inneren nicht als Text ausgegeben werden soll, sondern ganz normal von php umgesetzt werden soll...
 
Hm...
Dies zeigt alles als Text:

Code:
[COLOR=#000000][FONT=monospace]
if ( $instance['status']=='print' ) {[/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]echo '[/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]&lt;?php [/FONT][/COLOR][COLOR=#006600][FONT=monospace]if([/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]function_exists[/FONT][/COLOR][COLOR=#006600][FONT=monospace](\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'stbHighlightText\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace])) [/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]stbHighlightText[/FONT][/COLOR][COLOR=#006600][FONT=monospace](\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'Der aktuelle <a href="\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace].[/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]$instance[/FONT][/COLOR][COLOR=#006600][FONT=monospace][\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'post\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace]].\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'">\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace].[/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]$instance[/FONT][/COLOR][COLOR=#006600][FONT=monospace][\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'name\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace]].\[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'</a> befindet sich aktuell in Druck.\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace], \[/FONT][/COLOR][COLOR=#CC0000][FONT=monospace]'test\'[/FONT][/COLOR][COLOR=#006600][FONT=monospace]); [/FONT][/COLOR][COLOR=#0000CC][FONT=monospace]?&gt;[/FONT][/COLOR][COLOR=#000000][FONT=monospace]';

}[/FONT][/COLOR]
 
PHP:
if ( $instance['status']=='print' ) {
     echo '<?php if(function_exists('stbHighlightText')) stbHighlightText('Der aktuelle <a href="'.$instance['post'].'">'.$instance['name'].'</a> befindet sich aktuell in Druck.', 'test'); ?>';}
Wie kann ich das Problem lösen?
Indem du das richtig schreibst :)
PS: Ich hoffe man konnte mein Problem verstehen :)
Mal gucken... Was gibt die funktion stbHighlightText denn zurück?
suchst du das?
PHP:
if ($instance['status']=='print') {
  if(function_exists('stbHighlightText')) 
    stbHighlightText('Der aktuelle <a href="{$instance['post']}">{$instance['name']}</a> befindet sich aktuell in Druck.', 'test');
}

//oder anders:
if ($instance['status']=='print') {
  if(function_exists('stbHighlightText')) {
    stbHighlightText('Der aktuelle <a href="{$instance['post']}">{$instance['name']}</a> befindet sich aktuell in Druck.', 'test');
  } else {
    echo "funktion gibts nicht.";
  }
}

//oder nochmal...
if ($instance['status']=='print') {
  if(function_exists('stbHighlightText')) {
    echo stbHighlightText('Der aktuelle <a href="{$instance['post']}">{$instance['name']}</a> befindet sich aktuell in Druck.', 'test');
  } else {
    echo "funktion gibts nicht.";
  }
}

MfG
 
Werbung:
Zurück
Oben