<?php
class Prof {
function get_block($lines, $prof_num) {
$reserve = 200;
$strings = implode("", $lines);
$start_line = preg_grep("/1\.$prof_num\.1\./m", $lines);
$prof_num+=1;
$end_line = preg_grep("/1\.$prof_num\.1\./m", $lines);
$prof_num-=1;
$start_pos = mb_strpos($strings, end($start_line));
$end_pos = mb_strpos($strings, end($end_line));
$finalContent = mb_substr($strings, $start_pos-$reserve, $end_pos-$start_pos+$reserve);
$from = "1.$prof_num";
$prof_num+=1;
$to = "1.$prof_num";
$cutted = mb_substr($finalContent, strpos($finalContent, $from), strpos($finalContent, $to));
$cutted = preg_replace("/$to\..*/", "", $cutted);
// echo $cutted;
// $this->get_id($cutted);
// $this->get_name($cutted);
}
function get_id($txt) { //gettind id
$txt = explode("\n", $txt);
$id = preg_grep("/\d\.\sCode\s/", $txt);
$id = preg_replace("/\d\.\sCode\s\–\s/","", $id);
$id = preg_replace("/\t/", "",$id);
$id = preg_replace("/\.\s+/", "",$id);
foreach($id as $item) {
echo $item ."\n";
}
}
function get_name($txt) { //getting name
$txt = explode("\n", $txt);
$name = preg_grep("/\sName/", $txt);
$name = preg_replace("/\d\.\sName\–\s/","",$name);
$name = preg_replace("/\t/", "",$name);
$name = preg_replace("/\.\s+/", "",$name);
foreach($name as $item) {
echo $item ."\n";
}
}
Obj1 = new Prof();
Obj1 -> get_name(get_block(file('text.txt'))); //ERROR HERE!!!!!!!!
Как я могу получить get_id и get_name с помощью метода get_block?Вставка объектов PHP в базу данных
- get_block gets me the whole text from text file, starting from line number $prof_num.
- get_id gets me the id from the get_block text block. get_name just gets the name from
get_block.
Мне нужно написать эти методы (идентификатор и имя) в моей базе данных, но, как я знаю, я не могу это сделать, если бы я только смог получить текстовый блок с get_block.
Pls, спросите меня, если что-то, может быть, я просто не могу это объяснить. : D
Вы бы лучше публиковали фактический код, а не псевдокод, который технически неверен – RamRaider
Определите класс правильно и, возможно, мы сможем помочь вам – RiggsFolly
Посмотрите '' this-> '[RTM - Начните здесь] (http: //php.net/manual/en/language.oop5.basic.php) – RiggsFolly