Kann man auf eine einfache art die zeilen eines textes brechnen?
z.b.
Code: Alles auswählen
$txt = ' Mein Text
hat
3 Zeilen';
Code: Alles auswählen
explode('\n', $txt);
Danke
Code: Alles auswählen
$txt = ' Mein Text
hat
3 Zeilen';
Code: Alles auswählen
explode('\n', $txt);
Weil man noch zusätzlich count() dazunehmen muss oder weil es mehr Performance kostet?Ambience hat geschrieben:hmm ne, da ist mir die explode version schon lieber..
Das gibt bei mir "test" aus. Warscheinlich liegt das Problem woanders? Da ist ja sicher noch mehr Code drumrum - oder schreibst du wirklich gerade dein erstes Hallo Welt Programm?Ambience hat geschrieben:<?php
echo "test";
?>
Code: Alles auswählen
function parse_php($text)
{
$line_rows = explode("\n", $text);
$lines = count($line_rows);
$text = htmlentities($text);
$text = preg_replace('/(\<\?php|\<\?)/is', '<font color="red">test</font>', $text);
return $text;
}
Code: Alles auswählen
<?php
function parse_php($text)
{
$line_rows = explode("\n", $text);
$lines = count($line_rows);
$text = htmlentities($text);
$text = preg_replace('/(\<\?php|\<\?)/is', '<font color="red">test</font>', $text);
return $text;
}
$text = "
<?php
//
// Testkommentar
//
?>";
echo nl2br(parse_php($text));
?>
Code: Alles auswählen
<?php
function parse_php($text)
{
$line_rows = explode("\n", $text);
$lines = count($line_rows);
$text = str_replace('<', '<', $text);
$text = preg_replace('/(\<\?php|\<\?)/is', '<span style="color:#ff0000;font-weight:bold;">$1</span>', $text);
return $text;
}
$text = "
<?php
//
// Testkommentar
//
?>";
echo nl2br(parse_php($text));
?>