Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
$string = 'if(mb_strlen($username, "UTF-8") < 2 || mb_strlen($username, "UTF-8") > 12 ) {
array_push($errors, "Името трябва да е между 2 и 12 символа.");
}
if(!strpos($link, "vbox") || !strpos($link, "youtube")) {
array_push($errors, "Линкът трябва да е от Vbox7 или YouTube.");
}
if(mb_strlen($title, "UTF-8") < 3 || mb_strlen($title,"UTF-8") > 23) {
array_push($errors, "Заглавието трябва е между 3 и 25 символа.");
}';
$exploded = explode("\n", $string);
echo count($exploded);
<?php
if(isset($_POST['submit'])) {
$code = highlight_string($_POST['php'], true);
$code = preg_replace("/\[php\](.+?)\[\/php\]/i", "<pre class='phpcode'>$1</pre>", $code);
echo $code;
$count = explode("\n", $_POST['php']);
echo count($count)-2;
}
?>
relax4o каза:PHP:<?php if(isset($_POST['submit'])) { $code = highlight_string($_POST['php'], true); $code = preg_replace("/\[php\](.+?)\[\/php\]/i", "<pre class='phpcode'>$1</pre>", $code); echo $code; $count = explode("\n", $_POST['php']); echo count($count)-2; } ?>
Ето така. И не се чуди защо е -2. Това е така, защото ти взимам кода директно от ПОСТ метода и ти махам 2 броя \n , които са [ php] и [ /php]
<?php
if(isset($_POST['submit'])) {
$code = highlight_string($_POST['php'], true);
$count = explode("\n", $_POST['php']);
$asd = implode(range(1, count($count)-2), '<br />');
$code = preg_replace("/\[php\](.+?)\[\/php\]/i", "<table style='width: 600px; margin: 0 auto; border: 1px solid #e3e3e3;'><tr><td style='width: 20px; padding: 2px; border: 1px solid #e3e3e3; background: #F1F1F1; font: 13px Verdana; text-align: center;'>".$asd."</td><td><pre style='width: 572px; overflow: auto; font: 13px verdana; margin: 0; padding: 0;'>$1</pre></td></tr></table>", $code);
echo $code;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="bg-BG" xml:lang="bg-BG" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> - Оцветяване на PHP Code - </title>
<meta http-equiv="Content-Type" content="text/html;charset=windows-1251"/>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
background-color: #f7f7f7;
font-family: Arial,Verdana;
font-size: 14px;
}
div.main {
width: 850px;
height: 100%;
margin: 0 auto;
}
div.splash {
background-color: #ddd;
border: 2px solid #c0c0c0;
margin-top: 5px;
margin-bottom: 5px;
padding: 10px;
}
.linenum {
background-color: #FDECE1;
text-align: center;
border: 1px solid #cc6666;
padding: 0px 1px 0px 1px;
font-family: Courier New, Courier;
float: left;
width: 17px;
margin: 3px 0px 30px 0px;
}
.code {
font-family:Courier New, Courier;
}
.linetext {
text-align: left;
background: white;
border: 1px solid #cc6666;
padding: 0px 1px 0px 8px;
font-family: Courier New, Courier;
margin:3px 0px 30px 0px;
width:772px;
overflow:auto;
}
br.clear {
clear:both;
}
</style>
</head>
<body>
<div class="main">
<div class="splash">
<?php
function printCode($code, $lines_number = 0) {
if (!is_array($code)) $codeE = explode("\n", $code);
$count_lines = count($codeE);
$r1 = "<b> Код: </b><br />";
if ($lines_number){
$r1 .= "<div class=\"linenum\">";
foreach($codeE AS $line => $c) {
if($count_lines == '1') {
$r1 .= "1";
} else {
$r1 .= ($line == ($count_lines - 1)) ? "" : ($line+1)."<br />";
}
}
$r1 .= "</div>";
}
$r2 = "<div class=\"linetext\">";
$r2 .= highlight_string($code,1);
$r2 .= "</div>";
$r = $r1.$r2;
echo "<div class=\"code\">".$r."</div>\n";
}
if(isSet($_POST['submit'])) {
printCode(''.$_POST['php'].'',1);
} else {
echo "
<form method=\"POST\">
<textarea name=\"php\" rows=\"25\" cols=\"35\" wrap=\"virtual\" style=\"width:800px;\" tabindex=\"3\"></textarea><br />
<input type=\"submit\" name=\"submit\" value=\"Виж кода\" />
</form>";
}
?>
</div>
</div>
</body>
</html>