Web scraping publication from a google scholar profile via simplehtmldom PHP - php

I'm trying to scrape publication from a google scholar profile,but i have no idea how to scrape every publication from a profile, i know the maximum publication the profile page can show is 100 per page from this question :
Google Scholar profile scrape PHP
I just want to know how to apply the url to my php code so that i can get every publication from a profile and insert them to a array
I am able to put every publication in a single page to a array with this code:
<?php
set_time_limit(0);
include 'simple_html_dom.php';
$data = json_decode(file_get_contents('php://input'),true);
$scholarID = $data["gScholarID"];
$kodeDosen = $data["kodeDosen"];
$page = 1;
$offset = ($page - 1)* 100;
$cStart = 0+$offset;
$profile = 'https://scholar.google.com/citations?user='.$scholarID.'&hl=en&cstart='.$cStart.'&view_op=list_works&pagesize=100';
$html = file_get_html($profile);
$table = $html->find('#gsc_a_t',0);
$rowData = array();
foreach($table->find('tr.gsc_a_tr') as $row){
$paperjudul = $row->find('td.gsc_a_t a', 0)->plaintext;
$paper['kodeDosen'] = $kodeDosen;
$paper['judul'] = $paperjudul;
$cited = $row->find('td.gsc_a_c', 0)->plaintext;
if($cited === ''){
$cited = 0;
}
$cited = preg_replace('/[\*]+/', '', $cited);
$paper['citedBy'] = $cited;
$paper['namaJurnal'] = $row->find('td.gsc_a_t .gs_gray', 1)->plaintext;
if($paper['namaJurnal'] === ''){
$paper['namaJurnal'] = 'n/a';
}
$paper['periode'] = $row->find('td.gsc_a_y', 0)->plaintext;
if($paper['periode'] === ' '){
$paper['periode'] = 'n/a';
}
$paper['status'] = 'Published';
$rowData[] = $paper;
}
print_r($rowData);
?>
I just want to know how to apply this code to multiple pages to get all publication from a google scholar profile

I found a method that works, first, i create a loop that searches the web page for an indication that the page has no publication to show and inserts the url that contains the publication which i then loop to scrape the publication within the url.
This is the code that i used:
<?php
set_time_limit(0);
include 'simple_html_dom.php';
include 'connectdb.php';
$scholarID = $_GET["gScholarID"];
$kodeDosen = $_GET["kodeDosen"];
$page = 1;
$finalPage = false;
$sqlTest = 'INSERT INTO tbl_publikasi(kodeDosen,jenis,namaJurnal,judul,status,tipePublikasi,periode,tahun,citedCount) VALUES ';
$response = array();
while (!$finalPage) {
$offset = ($page - 1)* 100;
$cStart = 0+$offset;
$profile = 'https://scholar.google.com/citations?user='.$scholarID.'&hl=en&cstart='.$cStart.'&view_op=list_works&pagesize=100';
$html = file_get_html($profile);
if(is_object($html)){
$empty = $html->find('td.gsc_a_e',0);
if($empty){
$finalPage = true;
unset($html);
}
else{
$urlArray[] = $profile;
$page++;
}
}
else{
$response['success'] = 0;
$response['message'] = "URL tidak valid ";
}
}
if($finalPage){
foreach ($urlArray as $urlPublikasi) {
$html = file_get_html($urlPublikasi);
$table = $html->find('#gsc_a_t',0);
$rowData = array();
if($table){
foreach($table->find('tr.gsc_a_tr') as $row){
$paper['kodeDosen'] = $kodeDosen;
$paperjudul = $row->find('td.gsc_a_t a', 0)->plaintext;
$paper['judul'] = $paperjudul;
$cited = $row->find('td.gsc_a_c', 0)->plaintext;
if($cited === ''){
$cited = 0;
}
$cited = preg_replace('/[\*]+/', '', $cited);
$paper['citedBy'] = trim($cited);
$paper['jenis'] = 'Scholar';
$paper['namaJurnal'] = $row->find('td.gsc_a_t .gs_gray', 1)->plaintext;
if($paper['namaJurnal'] === ''){
$paper['namaJurnal'] = 'n/a';
}
$paper['periode'] = 'n/a';
$paper['tahun'] = $row->find('td.gsc_a_y', 0)->plaintext;
if($paper['tahun'] === ' '){
$paper['tahun'] = '0000';
}
$paper['tipePublikasi'] = 'Scholar';
$paper['status'] = 'Published';
$rowData[] = $paper;
}
foreach ($rowData as $paperValue) {
$judul = $paperValue['judul'];
$jenis = $paperValue['jenis'];
$citedCount = $paperValue['citedBy'];
$namaJurnal = $paperValue['namaJurnal'];
$periode = $paperValue['periode'];
$tahun = $paperValue['tahun'];
$status = $paperValue['status'];
$tipePublikasi = $paperValue['tipePublikasi'];
$sqlTest .= "('".$kodeDosen."','".$jenis."','".$namaJurnal."','".$judul."','".$status."','".$tipePublikasi."','".$periode."','".trim($tahun)."','".$citedCount."'),";
}
$query = rtrim($sqlTest, ',');
$query .= "ON DUPLICATE KEY UPDATE idPublikasi=LAST_INSERT_ID(idPublikasi), kodeDosen = VALUES(kodeDosen), jenis = VALUES(jenis),
namaJurnal=VALUES(namaJurnal),status=VALUES(status),
tipePublikasi = VALUES(tipePublikasi),periode=VALUES(periode),tahun = VALUES(tahun),citedCount = VALUES(citedCount)";
}
else{
$response['success'] = 0;
$response['message'] = "Tabel Publikasi tidak ditemukan ";
}
}
if (mysqli_query($conn, $query)) {
$response['success'] = 1;
$response['message'] = "Array Uploaded Successfully";
}
else {
$response['success'] = 0;
$response['message'] = "Array Upload Failed, Alasan : ".mysqli_error($conn);
}
}
else{
$response['success'] = 0;
$response['message'] = "Gagal ditemukan ";
}
echo json_encode($response);
?>

Related

unable to insert multiple array data from dynamic generated field?

I am unable to enter multiple data, it enter only single data. I have tried using for loop and then entering data, using 3 user and 2 task, there is an error previously offset.
public function add($postData)
{
// dd($postData);
$c = count($postData['user_name']);
$t = count($postData['task_name']);
for ($i = 0; $i < $c; $i++) {
$user_name = $postData['user_name'][$i];
$user_email = $postData['user_email'][$i];
$data['insert']['user_name'] = $user_name;
$data['insert']['user_email'] = $user_email;
}
for ($j = 0; $j < $t; $j++) {
$task_name = $postData['task_name'][$j];
$data['insert']['task_name'] = $task_name;
}
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
if ($result == true) {
$response['status'] = 'success';
$response['message'] = 'Project created';
} else {
$response['status'] = 'danger';
$response['message'] = DEFAULT_MESSAGE;
}
return $response;
}
As Per lack of question details attached, I am supposing that you want to insert multiple task entry with project name, description etc.
Here is updated code:
<?php
// dd($postData);
$username = $postData['username'];
$user_email = $postData['user_email'];
$task_name = $postData['task_name'];
foreach ($username as $key => $value) {
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['username'] = $value;
$data['insert']['user_email'] = $user_email[$key];
$data['insert']['task_name'] = $task_name[$key];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
}

Datatables very slow load on Codeigniter

I have to get data from fingerprint machine. Everything in my code run and works, but if I show all employee data, it loads very slow.
I have create datatables by codeigniter and ajax call to view. My code like below
// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$year = $this->input->post("year");
$month = $this->input->post("month");
$dept = $this->input->post("dept");
$where = $year.'-'.$month.'-';
$shifts = $this->m_general->get_data('tb_shift')->result();
$rows = $this->m_employee->attendance($where)->result_array();
if($dept=='5'){
$pin_emp = $this->m_general->get_data('tb_employee')->result();
}else{
$pin_emp = $this->m_general->check_data('tb_employee',array('emp_dept'=>$dept))->result();
}
$loc_machine= $this->m_general->get_data('tb_pkm')->result();
$roaster = $this->m_employee->list_schedule_emp($where)->result_array();
$holiday = $this->m_general->get_data('tb_holiday')->result();
$total_days = tglakhir($year,$month);
$dates = array();
$people = array();
$data = array();
foreach ($rows as $row) {
if (empty($row['date']) || empty($row['pin'])) {
continue; // no date or sn, nothing to print for this row...
}
// in array assures unique values
if (!in_array($row['date'], $dates)) {
$dates[] = $row['date'];
}
// this may seem convoluted, take your time to understand
$people[$row['date']][$row['pin']] = $row;
$array_emp[$row['date']][$row['pin']][] = $row;
}
foreach ($roaster as $rs) {
if (empty($rs['date']) || empty($rs['id_nip'])) {
continue; // no date or sn, nothing to print for this row...
}
// this may seem convoluted, take your time to understand
$get_rs[$rs['date']][$rs['id_nip']] = $rs;
$dt_rs[$rs['date']][$rs['id_nip']][] = $rs;
}
foreach($pin_emp AS $q){
$array_pin[]=$q->emp_pin;
$details[$q->emp_pin] = $q;
}
foreach($holiday AS $hday){
$get_hday[$hday->date_holiday] = $hday;
}
foreach($loc_machine AS $list_machine){
$lm[$list_machine->id_machine] = $list_machine;
}
for($m=1; $m <= $total_days; $m++){
if($m<10){
$m = '0'.$m;
}else{
$m = $m;
}
$date[]=$m;
}
foreach($shifts AS $shift_e){
$array_shift[$shift_e->id_shift] = $shift_e;
$ar_shift[]=$shift_e->id_shift;
}
foreach ($array_pin AS $id){
$name = $details[$id]->emp_name;
$shift = $details[$id]->emp_shift;
$id_machine = $details[$id]->emp_reg_sn;
if(isset($lm[$id_machine])){
$loc_machine= $lm[$id_machine]->pkm_name;
}
$date_range = array();
foreach($date AS $date_col){
$day = date('D', strtotime($year.'-'.$month.'-'.$date_col));
$today = date('Y-m-d');
$full_day = $year.'-'.$month.'-'.$date_col;
$s_in = '';
$s_out = '';
$time_in = '';
$time_out = '';
$t_in = '';
$t_out = '';
$finger_tap = '';
$diff_in = '';
$diff_out = '';
$diff = null;
$diff2 = null;
$late = '00:00:00';
$r = $date_col;
$title = '';
$date_holiday= '';
if (ISSET($get_hday[$full_day])==TRUE) {
$date_holiday = $get_hday[$full_day]->date_holiday;
$title = $get_hday[$full_day]->note_holiday;
}
foreach ($dates as $key) {
$shift_detail= $array_shift[$shift]->code_shift;
if(isset($get_rs[$full_day][$id]['id_shift_emp']) && $get_rs[$full_day][$id]['id_shift_emp']!=''){
$shift = $get_rs[$full_day][$id]['id_shift_emp'];
$shift_detail = $array_shift[$shift]->code_shift;
}
if (isset($people[$key][$id]['date']) && $people[$key][$id]['date'] == $key) {
foreach ($array_emp[$key][$id] AS $dtl){
if(isset($get_rs[$key][$id]['id_shift_emp']) && $get_rs[$key][$id]['id_shift_emp']!=''){
$shift = $get_rs[$key][$id]['id_shift_emp'];
}
$shift = $dtl['emp_shift'];
$date_time = $dtl['date_time'];
if(($shift==5)OR($shift==7)OR($shift==9)OR($shift==11)OR($shift==12)OR($shift==14)){
$r = $date_col+1;
}
if(substr($key,8,2)==$date_col){
$status_code= $dtl['status_code'];
$status_note= $dtl['att_status'];
$first_in = strtotime($year.'-'.$month.'-'.$date_col.' '.$array_shift[$shift]->first_check);
$last_out = strtotime($year.'-'.$month.'-'.$r.' '.$array_shift[$shift]->last_check);
$shift_in = $array_shift[$shift]->in_shift;
$shift_out = $array_shift[$shift]->out_shift;
$s_in = strtotime($year.'-'.$month.'-'.$day.' '.$shift_in);
$s_out = strtotime($year.'-'.$month.'-'.$day.' '.$shift_out);
$finger_tap = strtotime($date_time);
$shift_detail= $array_shift[$shift]->code_shift;
foreach($ar_shift AS $id_shift){
if ($shift==$id_shift) {
$currdiff = abs($finger_tap - $first_in);
if (is_null($diff) || $currdiff < $diff) {
$diff = $currdiff;
$time_in = date('H:i:s',strtotime($date_time));
$t_in = strtotime($date_time);
if(($t_in-$s_in)>0){
$diff_in = gmdate('H:i:s',$t_in-$s_in);
}else{
$diff_in = $late;
}
}
$currdiff2 = abs($finger_tap - $last_out);
if (is_null($diff2) || $currdiff2 < $diff2) {
$diff2 = $currdiff2;
$time_out = date('H:i:s',strtotime($date_time));
$t_out = strtotime($date_time);
if(($t_out-$s_out)>0){
$diff_out = $late;
}else{
$diff_out= gmdate('H:i:s',$s_out-$t_out);
}
}
}
}
}
if(($shift==5)OR($shift==7)OR($shift==9)OR($shift==11)OR($shift==12)OR($shift==14)){
if ($day==$r) {
$shift_out = $array_shift[$shift]->out_shift;
$s_out = strtotime($year.'-'.$month.'-'.$r.' '.$shift_out);
$finger_tap = strtotime($date_time);
foreach($ar_shift AS $id_shift){
if ($shift==$id_shift) {
$currdiff2 = abs($finger_tap - $last_out);
if (is_null($diff2) || $currdiff2 < $diff2) {
$diff2 = $currdiff2;
$time_out = date('H:i:s',strtotime($date_time));
$t_out = strtotime($date_time);
if(($t_out-$s_out)>0){
$diff_out = $late;
}else{
$diff_out= gmdate('H:i:s',$s_out-$t_out);
}
}
}
}
}
}
$status = '<i class="material-icons col-green">check_box_outline_blank</i>'.$shift_detail.'';
if($year.'-'.$month.'-'.$date_col < $today){
$status = '<i class="material-icons col-red">fiber_manual_record</i>'.$shift_detail.'';
}
if(($day == 'Sun') OR ($day == 'Sat')){
$status='<a href="javascript:change_status_att(\''.$id.'\',\''.$name.'\',\''.$full_day.'\')" class="btn btn-md bg-red waves-effect" data-toggle="tooltip" data-placement="top" title="Libur">off</button>';
}
if($date_holiday == $full_day){
$status = '<i class="material-icons col-red">today</i>OFF';
}
if($time_in!=''){
if($time_in==$time_out){
$status = '<i class="material-icons col-red">brightness_6</i>'.$shift_detail.'';
}
if ($status_code!='') {
$status = '<i class="material-icons col-orange">sim_card_alert</i>'.$shift_detail.'';
}
}
if($time_in!=$time_out){
$status = '<i class="material-icons col-green">check_box</i>'.$shift_detail.'';
}
if($time_in=='00:00:00'){
$status = '<i class="material-icons col-orange">sim_card_alert</i>'.$shift_detail.'';
}
}
}
}
$date_range[] = $status;
}
$first = array(
''.$id.'',
$name,
$loc_machine
);
$data[] = array_merge($first,$date_range);
}
$output = array(
"draw" => $draw,
"recordsTotal" => '',
"recordsFiltered" =>'' ,
"data" => $data
);
$this->output->set_content_type('application/json')->set_output(json_encode($output));
}
This code runs and works, but need about 10 second for load.
Can somebody help Me what I have to do to be fast this load?
UPDATE
after I analysis my code, the slow load data because datatables say "data was truncated". But when I load on small data(filtered), It was fine.
problem still same when I get all data from database.
To make it faster, you first need to know what is slow. To do that, you need to use debugging tools, like this one and timestamps.
Then, once you get logs with the duration of your processes, you can analyze it to know which part of your code is slow.
Then, try to optimize it. And if you can’t, edit your question to focus on the slow part or post a new one.

Does not display the result of parsing

Good afternoon, please help me. At me when parsing the result of parsing is not displayed.
link my php file https://dropmefiles.com/cv4Q2
Please correct where I was wrong. Or help to rewrite a little code so that it displays the result of the parser.
Already tried all the options, it does not work in any way. My knowledge here is not enough.
1 file
part 1
function getForecastXML($cid='579432') {
$cid = "579432";
$hoffset = "4";
$appid= "d86ad74d22ce9cc528d8baee65acd408";
$lang= "ru";
$days = array();
$xml = #file_get_contents("http://api.openweathermap.org/data/2.5/forecast?id=$cid&mode=xml&appid=$appid&lang=$lang&type=like");
if ($xml===false) { return;} else {
$xml = simplexml_load_string($xml);
$cityname = (string)$xml->location->name;
$weekdays[0] = "Воскресенье";
$weekdays[1] = "Понедельник";
$weekdays[2] = "Вторник";
$weekdays[3] = "Среда";
$weekdays[4] = "Четверг";
$weekdays[5] = "Пятница";
$weekdays[6] = "Суббота";
if (count($xml->forecast->time)>0){
foreach ($xml->forecast->time as $fpart) {
$forecast = array();
$attr = $fpart->attributes();
$forecast['t']['min'] = (string)round(($fpart->temperature->attributes()->min)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['min'] = $forecast['t']['min'] > 0 ? "+".$forecast['t']['min'] : $forecast['t']['min'];
$forecast['t']['max'] = (string)round(($fpart->temperature->attributes()->max)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['max'] = $forecast['t']['max'] > 0 ? "+".$forecast['t']['max'] : $forecast['t']['max'];
$forecast['p']['min'] = (string)round($fpart->pressure->attributes()->value,0,PHP_ROUND_HALF_UP);
// $forecast['p']['max'] = (string)$fpart->PRESSURE->attributes()->max;
$forecast['w']['min'] = (string)round($fpart->windSpeed->attributes()->mps,0,PHP_ROUND_HALF_UP);
//$forecast['w']['max'] = (string)$fpart->WIND->attributes()->max;
//$forecast['w']['rumb'] = (string)$fpart->WIND->attributes()->direction;
$forecast['h']['min'] = (string)$fpart->humidity->attributes()->value;
//$forecast['h']['max'] = (string)$fpart->RELWET->attributes()->max;
$forecast['symb'] = (string)$fpart->symbol->attributes()->name;
$forecast['pict'] = (string)$fpart->symbol->attributes()->var;
$date = date('c',strtotime($hoffset.' hours',strtotime($attr['from'])));
$hour = date('H',strtotime($date));
$forecast['timestamp'] =strtotime($date);
$date = strtotime($date);
$dayofweek = date('w',$date);
$date = $weekdays[$dayofweek]." ".date('d.m',$date);
if ($forecast['timestamp'] > time()){
$days[$date][$hour] = $forecast;
}
}
} else {$days=array();}
}
//return array($cityname,$days);
return [$cityname => $days];
//echo [$cityname => $days];
}
part 2
$outputData = array();
if (count($this->forecast) > 0) {
foreach ($this->forecast as $date => $daypart) {
$outputData[] = $date;
foreach ($daypart as $dp => $data) {
$outputData[] = str_pad($dp, 2, '0', STR_PAD_LEFT);
$outputData[] = $data['symb'];
$outputData[] = $data['t']['min'];
$outputData[] = $data['t']['max'];
if (($data['p']['min']) > 0) {
$outputData[] = "Давление " . round($data['p']['min'] * 0.75006375541921) . "мм. рт. ст.";
}
}
}
} else {
$outputData[] = "В данный момент информация о погоде отсутствует";
}
echo implode(' ', $outputData);

Laravel - Import excel keep looping

Dears,
i have an excel file with 5K rows and i'm importing it to my table in the DB successfully.
But the error, when the system finish all the rows, it keeps looping and the page doesn't stop running and not redirecting to my view.
My controller:
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->select('id')->get()->toArray();
if(empty($res)) {
$polic = new policies();
$polic->cust_id = $row['custno'];
$polic->policy = '';
$polic->bord_date = $borddate;
$polic->client_id = $row['clientid'];
$polic->client_no = $row['clientno'];
$polic->client_name = $row['clientname'];
$polic->draft_no = $row['draftno'];
if ($row['status'] == '') {
$polic->status = '';
} else {
$polic->status = $row['status'];
}
$polic->due_date = $duedate;
if ($row['curno'] == 'USD') {
$polic->currency = 1;
} else {
$polic->currency = 0;
}
$polic->amount = $row['amnt'];
$polic->zone = $row['zone'];
$polic->broker_id = $row['brokercode'];
$polic->broker_name = $row['brokername'];
$polic->remarks = $row['remarks'];
$polic->phone = $row['phone'];
$polic->insured_name = $row['insname'];
// $polic->cust_id = $row['valuedate'];
$polic->address = ''; //address
if (trim($row['status']) == 'P') {
$polic->paid_at = date('Y-m-d');
}
$polic->new = 1; //address
$polic->save();
}
else {
//am updating the imported date in the DB
}
what is very strange that in my localhost is working fine, but in digitaloceans cloud, keep looping without redirecting.
Thanks for your help.
I can be because you have 5000 rows to insert and 5000 insert operation consumes lots of memory. What you can try is batch insert operation.
In your policies.php make all fields fillable
protected $fillable=['cust_id ','policy','bord_date','client_id','client_no','client_name ','draft_no','bord_date','status','due_date','currency','amount','zone','broker_id','broker_name','remarks','phone','insured_name','address','paid_at','new'];
And on your excel file import use exists rather than getting collections.
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
$data=[];
$i=0;
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->exists();
if(!$res) {
$i++;
$data[$i]['cust_id ']=$row['custno'];
$data['policy'] = '';
$data['bord_date'] = $borddate;
$data[$i]['client_id'] = $row['clientid'];
$data[$i]['client_no'] = $row['clientno'];
$data[$i]['client_name'] = $row['clientname'];
$data[$i]['draft_no'] = $row['draftno'];
if ($row['status'] == '') {
$data[$i]['status'] = '';
} else {
$data[$i]['status'] = $row['status'];
}
$data[$i]['due_date'] = $duedate;
if ($row['curno'] == 'USD') {
$data[$i]['currency'] = 1;
} else {
$data[$i]['currency'] = 0;
}
$data[$i]['amount'] = $row['amnt'];
$data[$i]['zone'] = $row['zone'];
$data[$i]['broker_id'] = $row['brokercode'];
$data[$i]['broker_name'] = $row['brokername'];
$data[$i]['remarks'] = $row['remarks'];
$data[$i]['phone'] = $row['phone'];
$data[$i]['insured_name'] = $row['insname'];
// $data[$i]['cust_id'] = $row['valuedate'];
$data[$i]['address'] = ''; //address
if (trim($row['status']) == 'P') {
$data[$i]['paid_at'] = date('Y-m-d');
}
$data[$i]['new'] = 1; //address
}
else {
//am updating the imported date in the DB
}
}
policies::insert($data);

Insert Url last 2 characters in database php

I am trying to insert last 2 chararcters of Url into my database.When i insert everytime it takes some number like "2147483647".How to insert the correct last 2 chararcters of Url.
'$array = json_decode(stripslashes($_POST['data']));
for($i = 0, $l = sizeof($array); $i < $l; $i++){
$obj = $array[$i];
if($obj->{'leaf'} == true){
$leaf = 1;
} else{
$leaf = 0;
}
if($obj->{'parentId'} == null){
$parentID = 'null';
} else{
$parentID = $obj->{'parentId'};
}
if($obj->{'Duration'}==''){
$duration = 0;
} else{
$duration = $obj->{'Duration'};
}
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$gantt_id = substr(strrchr($url, '='), 1);
/*if($obj->{'gantt_id'}==null){
$gantt_id = 0;
} else{
$gantt_id = $obj->{'gantt_id'};
}
*/
$q = 'INSERT INTO j_gantt_tasks SET Name = "'.$obj->{'Name'}.'", StartDate = "'.$obj->{'StartDate'}.'", EndDate = "'.$obj->{'EndDate'}.'",
Duration = "'.$obj->{'Duration'}.'", DurationUnit = "'.$obj->{'DurationUnit'}.'", PercentDone = "'.$obj->{'PercentDone'}.'", Cls = "'.$obj->{'Cls'}.'", gantt_id="'.$gantt_id.'",
parentId = "'.$obj->{'parentId'}.'"';
$r = mysql_query($q);
if(!$r){
echo db_error($q);
}
$obj->{'id'} = mysql_insert_id();
}
echo json_encode($array);'
give a try to substring
$url = (!empty($_SERVER['HTTPS'])) ?
"https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] :
"http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$last2 = substring($url,-2);

Categories