Тестовая работа
Code (PHP) :
Задание 3.3 (б,в)
$search = 'Программист';
$search2 = 'Програ(м|мм)ист';
$replace = 'Культурист';
$i=0;
//1
$txx = file('text.txt');
foreach ($txx as $txxx) {
if (preg_match("/^".$search."/", $txxx)) {
echo $txxx.'<br>';
}
}
//2
$i = 0;
foreach ($txx as $txxx) {
if ((preg_match("/^".$search."/i", $txxx))||(preg_match("/".$search."$/i", $txxx))) {
echo $txxx.'<br>';
}
$i++;
}
//3
$i = 0;
foreach ($txx as $txxx) {
if ((preg_match("/^".$search."/i", $txxx))|(preg_match("/".$search."$/i", $txxx)||(preg_match('/(\(('.$search2.'))/i', $txt))) {
echo $txxx.'<br>';
}
$i++;
}
//3.2
$i = 0;
foreach ($txx as $txxx) {
$txxx = preg_replace('/'.$search.'/i', $replace, $txxx);
echo $txxx;
$i++;
}
// seacrh 'слово и дело';
foreach ($txx as $txxx) {
$text = preg_replace('/\"([^>]+)\"/', '($1)', $txxx); //заменяем двойные кавычки на скобки
$text = preg_replace('/\'([^>]+)\'/', '($1)', $txxx); //заменяем одинарные кавычки на скобки
echo $text;
$i++;
}
Code (PHP) :
$test = '1234.765';
function checktest(test) {
if (preg_match('/^(\d+).(\d+)$/', $test)) { echo 'ok '; }
$num = str_split($test);
$l = sizeof($num);
$i = 0;
$dt = false; // isset dotted
foreach ($num as $nm) {
$wrong = true; //wrong input data
if ((is_numeric($nm))||($nm=='.')) {
echo $nm.'><>/br>';
$wrong=false;
}
if (($nm=='.')&&($i>0)&&($i><>$l-1)) {
echo $nm.'><>/br>';
$dt=true;
$wrong=false;
}// check dotted and range
$i++;
}
if ((!$wrong)&&($dt)) { echo 'ok'; }
checktest($test);
Задание 7(a).
Code (JavaScript) :
Задание 7 (b).
<? php $a = 'hallo world!'; ?> <html> <head> <script> var a = '<? echo $a; ?>'; alert (a); </script> </head> <body> </body> </html>
Code (JavaScript) :
Задание 2.
//создание iframe
rcvNode.open();
rcvNode.write("<html><head><title>ActiveX</title>")
rcvNode.write("<script src='/js/browser.js'></sc"+"ript>")
rcvNode.write("<script src='/server_push/iframe.js'></scr"+"ipt>")
rcvNode.write("</head><body></body></html>")
rcvNode.close();
//отправка post запроса в iframe
IEFrameDocument.parentWindow.postToIframe({prop:'val'}, '/server/test.php', 'frame3')Code (JavaScript) :
Задание 3.3
<style>
div.container{
position:absolue;
left:0px;
right:0px;
}
</style>
<script>
var objBody=document.getElementsByTagName("body").item(0);
var conti=document.createElement("div");
conti.setAttribute('class','container');
objBody.insertBefore(conti,objBody.firstChild);
</script>
Code (JavaScript)
Задание 5.
Задание 8.
$txt = file('data.txt');
foreach ($txx as $txxx) {
$txt = preg_replace (/'\[title\]'/,$regs[title], $txt);
$txt = preg_replace (/'\[autor\]'/,$regs[autor], $txt);
$txt = preg_replace (/'\[copyright\]'/,$regs[copyright], $txt);
}
Code (JavaScript) :
a = [10,null,1,4,null,'javascript'];
a[1] = {"id":"10", "pid":"15"};
a[4] = ['php', 5, 6];
for (i=0; i<a.length; i++) {
if (typeof a[i] == 'object') {
for (var ii in a[i]) {
iii = ii;
if (ii*1>0) { iii = '1'+ii; }
console.log(iii+':'+a[i][ii]);
}
} else {
console.log(i+':'+a[i]);
}
}Задание 8.
Code (PHP) :
Задание 10.
<?php
$arTest = array(
'A'=>array(
'A1'=>array(
'A11'=>null,
'A12'=>null),
'A2'=>null,
'A3'=>array(
'A31'=>null),
'A4'=>null),
'B'=>null,
'C'=>array(
'C1'=>null,
'C2'=>null),);
//1
$res = array();
$resA = array();
$resB = array();
$resC = array();
//1
foreach ( $arTest as $key => $value ) {
if (gettype($value)=='array') {
array_push($resA,$key);
array_push($res,$key);
foreach ( $value as $key2 => $value1 ) {
if (gettype($value1)=='array') {
array_push($res,$key2);
array_push($resB,$key2);
foreach ( $value1 as $key3 => $value2 ) {
array_push($res,$key3);
array_push($resC,$key3);
}
}//eof if 2
else {
array_push($res,$key2);
array_push($resB,$key2);
}
}
}//eof if 1
else {
array_push($resA,$key);
array_push($res,$key);
}
}
//echo 'result:'.$a.$b.$c;
//1
foreach ($res as $value) {
echo $value;
}
echo '<br>';
//2
echo $res[2].' '.$res[3].' '.$res[1].' '.$res[4].' '.$res[6].' '.$res[5].' '.$res[4].' '.$res[0].' '.$res[8].' '.$res[10].' '.$res[11].' '.$res[9];
echo '<br>';
//3
$res2 = array_reverse($res);
foreach ($res2 as $value) {
echo $value;
}
echo '<br>';
//4
$resC = array_reverse($resC);
foreach ($resC as $value) {
echo $value;
}
$resB = array_reverse($resB);
foreach ($resB as $value) {
echo $value;
}
$resA = array_reverse($resA);
foreach ($resA as $value) {
echo $value;
}
Code (JavaScript) :
Задание 1.
//Проводка 220
function V() {
this.v = 220;
}
V.prototype.plug= function () {
//проверяем цепь
if ((this.switch)&&(this.lamp)) {
alert('Горит '+this.name+' на выключателе '+this.switchName);
}
}
//Переключатель
function Switch1() {
this.switch;
}
Switch1.prototype = Object.create(V.prototype);
Switch1.prototype.constructor = Switch1;
Switch1.prototype.switch = true;
Switch1.prototype.switchName = '1';
//Переключатель
function Switch2() {
this.switch;
}
Switch2.prototype = Object.create(V.prototype);
Switch2.prototype.constructor = Switch2;
Switch2.prototype.switch = true;
Switch2.prototype.switchName = '2';
//Лампа1
function Lamp1() {
this.lamp=true;
this.name = 'лампа1';
}
Lamp1.prototype = Object.create(Switch1.prototype);
Lamp1.prototype.constructor = Lamp1;
//Лампа2
function Lamp2() {
this.lamp=true;
this.name = 'лампа2';
}
Lamp2.prototype = Object.create(Switch2.prototype);
Lamp2.prototype.constructor = Lamp2;
var Lamp1 = new Lamp1();
var Lamp2 = new Lamp2();
//подключили обе лампы
Lamp1.plug();
Lamp2.plug();
Code (PHP) :
Задание 2.
$a = 'a'; $b = 'b'; $c = 'c';
list($a,$b,$c) = array ($c,$a,$b);
//Чему будут равны $a = ? ; $b = ?; $c = ?;
//Ответ $a = a; $b = 'b'; $c = 'c';
$a = 'a'; $b = 'b'; $c = 'c';
list($a,$b,$c) = array (&$b,&$c,&$a);
//Чему будут равны $a = ? ; $b = ?; $c = ?;
//Ответ: $a = a; $b = a; $c = a;
$x = 11.10 . 2007 - 1;
print $x;
//10.12007 - операции с дробными выражениями.Code (JavaScript) :
a)
var msg_1 = 'Сообщение 1-1';
var msg_2 = 'Сообщение 2-1';
function changeMsg()
{
var msg_1;
msg_1 = 'Сообщение 1-2';
msg_2 = 'Сообщение 2-2';
}
alert( msg_1 ); //сообщение 1-1;
alert( msg_2 ); //Сообщение 2-1
changeMsg();
alert( msg_1 );//Сообщение 1-2
alert( msg_2 );//Сообщение 2-2
b)
alert( parseInt('01') ); //ответ - 1
alert( parseInt('02') ); //ответ - 2
alert( parseInt('03') ); //ответ - 3
alert( parseInt('04') ); //ответ - 4
alert( parseInt('05') ); //ответ - 5
alert( parseInt('06') ); //ответ - 6
alert( parseInt('07') ); //ответ - 7
alert( parseInt('08') ); //ответ - 8
alert( parseInt('09') ); //ответ - 9
alert( parseInt('10') ); //ответ - 10
alert( parseInt('011') ); //ответ - 11