PHP french letters enconding - php

Currently, I'm working with PHP, and i'm parsing a CSV and saving it to DB.
I don't have any problem with that, just I have some french characters, that it's not showing correctly.
I took a look in all previous questions and I tried all suggested solutions, but no one solved my problem ....
Also, with "utf8_encode", it becomes more unreadable.
Here you can find all the code of the function:
if(date('l') == 'Thursday' or date('d') == 1)
{
$row = 1;
if (($handle = fopen("C:/Users/ASUS/Downloads/Exemple_extraction.csv", "r")) !== FALSE)
{
$this->createTable();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($row == 1){ $row++; continue; }
$num = count($data);
for ($c = 0; $c < $num; $c++)
{
$dataa = (explode(';', $data[$c]));
$dest = str_replace(' ', '', $dataa['27']);
echo($dataa['27']);echo '<br>';
switch($dest)
{
case 'Investissement':
$destination = 'Investir';
break;
case 'Non défini':
$destination = '';
break;
case 'Résidence principale':
$destination = 'Habiter';
break;
case 'Résidence secondaire':
$destination = 'Habiter';
break;
default:
$destination = '';
}
$tLogt = str_replace(' ', '', $dataa['26']);
switch($tLogt)
{
case 'Studio':
$tLogt = 'studio';
break;
case '1/2 pièces':
$tLogt = '2P';
break;
case '2/3 pièces':
$tLogt = '3P';
break;
case '3/4 pièces':
$tLogt = '4P';
break;
default:
if($tLogt == '4/5 pièces' || $tLogt == '5/6 pièces' || $tLogt == '5P DUPLEX')
{
$tLogt = '5P+';
}
}
if(str_replace(' ', '', $dataa['9']) != '')
{
$cp = substr(str_replace(' ', '', $dataa['9']), 0, 2);
}
else
{
$cp = '';
}
DB::table(date('l') . '_' . date("d_m_Y"))
->insert(['flReservataire' => $dataa['0'],
'flClient' => $dataa['1'],
'idProspect' => $dataa['2'],
'civility' => $dataa['3'],
'firstname' => $dataa['4'],
'lastname' => $dataa['5'],
'address1' => $dataa['6'],
'address2' => $dataa['7'],
'address3' => $dataa['8'],
'zipcode' => $dataa['9'],
'city' => $dataa['10'],
'codeInsee' => $dataa['11'],
'country' => $dataa['12'],
'flNpai' => $dataa['13'],
'phone' => $dataa['14'],
'workphone' => $dataa['15'],
'cellphone' => $dataa['16'],
'email1' => $dataa['17'],
'email2' => $dataa['18'],
'flStopMarketing' => $dataa['19'],
'age' => $dataa['20'],
'program' => $dataa['21'],
'region' => $dataa['22'],
'department' => $dataa['23'],
'seller' => $dataa['24'],
'typeLogt' => $dataa['25'],
'tailleLogt' => $dataa['26'],
'destination' => $dataa['27'],
'apport' => $dataa['28'],
'budget' => $dataa['29'],
'timelimit' => $dataa['30'],
'idOrigine' => $dataa['31'],
'typeContact' => $dataa['32'],
'typeAction' => $dataa['33'],
'dateAction' => $dataa['34'],
'comment' => $dataa['35'],
'typeActionFuture' => $dataa['36'],
'dateActionFuture' => $dataa['37'],
'levier' => $dataa['38'],
'support' => $dataa['39'],
'enreg' => $dataa['40'],
'destination_good' => $destination,
'typologie_good' => $tLogt,
'cp_good' => $cp,]);
}
}
fclose($handle);
$this->sendMail('emailSuccess');
}
else
{
$this->sendMail('emailError');
}
}
In all the "echo", I got the problem..
Any other suggestion plz?
Thanks alot
Kind Regards

My assumption would be that the CSV file uses a local encoding. To load it into correct internal representation you have to use iconv() from the local encoding (probably some ISO-8859 or WIN-12xx) to UTF8.
Also, to find out the correct encoding, use some decent text editor that supports switching encodings. Then simply find an option that makes the source readable.

Related

Creating default object from empty value through an array

I have read multiple threads here about the matter, although none of the solutions seem to be similar to mine. I would have attempted to fix this myself but unable to find anything similar I don't even know where to begin. Why am I getting this error, and what are the proper steps to resolve it?
function handleRequestsave_details()
{
$this->vbulletin->input->clean_array_gpc('p', array('fullname' => TYPE_STR,
'address_1' => TYPE_STR, 'address_2' => TYPE_STR, 'address_city' => TYPE_STR,
'address_state' => TYPE_STR, 'address_zip' => TYPE_STR, 'country' => TYPE_STR,
'phone' => TYPE_STR, 'company' => TYPE_STR));
if ($this->checkDetailsFields('details', $this->vbphrase['memarea_required_fields']))
{
$information = $this->buildInfoArray();
$this->vbulletin->userinfo['ma_info'] = $information;
$this->vbulletin->userinfo['usergroupid'] = $usergrpid;
if ($this->setCustomerNumber($information, $usergrpid))
{
$vbulletin->url = 'members.php?' . $vbulletin->session->vars['sessionurl'] . "do=details";
eval(print_standard_redirect('memarea_saved_details', true, true));
}
}
}
Here are the other functions included in this script, This is not my code it is simply an old product for vBulletin 3.x I am trying to update for my site. this portion throwing the error is when customers enter their billing details to save in their profile.
function checkDetailsFields($requested, $errormessage)
{
if (empty($this->vbulletin->GPC['fullname']) or empty($this->vbulletin->GPC['address_1']) or
empty($this->vbulletin->GPC['address_city']) or empty($this->vbulletin->GPC['address_zip']) or
empty($this->vbulletin->GPC['country']) or empty($this->vbulletin->GPC['phone']))
{
//$GLOBALS['error'] = $errormessage;
eval(standard_error($errormessage));
//$this->handleRequest($requested);
return false;
}
return true;
}
function buildInfoArray()
{
return array('fullname' => $this->vbulletin->GPC['fullname'], 'address_1' => $this->
vbulletin->GPC['address_1'], 'address_2' => $this->vbulletin->GPC['address_2'],
'address_city' => $this->vbulletin->GPC['address_city'], 'address_state' => $this->
vbulletin->GPC['address_state'], 'address_zip' => $this->vbulletin->GPC['address_zip'],
'country' => $this->vbulletin->GPC['country'], 'phone' => $this->vbulletin->GPC['phone'],
'company' => $this->vbulletin->GPC['company']);
}
function setCustomerNumber($ma_info, $usergroup = '', $usevb = true, $userinfo = '')
{
if ($usevb == false)
{
$this->vbulletin->userinfo = &$userinfo;
}
$fcust = $this->fields['custnum'];
$fpass = $this->fields['mpassword'];
$finfo = $this->fields['info'];
$userdm = datamanager_init('User', $this->vbulletin, ERRTYPE_ARRAY);
$userinfo = fetch_userinfo($this->vbulletin->userinfo['userid']);
$userdm->set_existing($userinfo);
if (!$this->vbulletin->userinfo["$fcust"] and !$this->vbulletin->userinfo["$fpass"])
{
$rand = rand($this->vbulletin->options['memarea_numstart'], $this->vbulletin->
options['memarea_numend']);
$num = $this->vbulletin->options['custnum_prefix'] . substr(md5($rand), 0, $this->
vbulletin->options['memarea_custnumleng'] - strlen($this->vbulletin->options['custnum_prefix']));
$userdm->set($fcust, $num);
$pass = substr(md5(time() . $num . $rand . rand(0, 2000)), 0, $this->vbulletin->
options['memarea_custnumleng']);
$userdm->set($fpass, $pass);
$this->sendCustomerInfo($this->vbulletin->userinfo['userid'], $this->vbulletin->
userinfo['username'], $this->vbulletin->userinfo['email'], $num, $pass);
}
if ($usergroup or $usergroup !== '' or $usergroup !== '0')
{
if ($usergroup != $this->vbulletin->userinfo['usergroupid'])
{
$ma_info['oldgroup'] = $this->vbulletin->userinfo['usergroupid'];
$userdm->set('usergroupid', $usergroup);
}
}
if ($ma_info)
{
$ma_info = serialize($ma_info);
$userdm->set($finfo, $ma_info);
}
$userdm->pre_save();
if (count($userdm->errors) == 0)
{
$userdm->save();
return true;
}
else
{
var_dump($userdm->errors);
return false;
}
}

Parsing returns an empty value

I make a parser of items from DotA 2 user inventory in the Steam service. Every time I try to parse user data, I get an empty value:
{"success":true,"items":[]}, but there are items in my Steam inventory.
My function to parse items:
public function loadMyInventory() {
if(Auth::guest()) return ['success' => false];
$prices = json_decode(Storage::get('prices.txt'), true);
$response = json_decode(file_get_contents('https://steamcommunity.com/inventory/'.$this->user->steamid64.'/570/2?l=russian&count=5000'), true);
if(time() < (Session::get('InvUPD') + 5)) {
return [
'success' => false,
'msg' => 'Error, repeat in '.(Session::get('InvUPD') - time() + 5).' сек.',
'status' => 'error'
];
}
//return $response;
$inventory = [];
foreach($response['assets'] as $item) {
$find = 0;
foreach($response['descriptions'] as $descriptions) {
if($find == 0) {
if(($descriptions['classid'] == $item['classid']) && ($descriptions['instanceid'] == $item['instanceid'])) {
$find++;
# If we find the price of an item, then move on.
if(isset($prices[$descriptions['market_hash_name']])) {
# Search data
$price = $prices[$descriptions['market_hash_name']]*$this->config->curs;
$class = false;
$text = false;
if($price <= $this->config->min_dep_sum) {
$price = 0;
$text = 'Cheap';
$class = 'minPrice';
}
if(($descriptions['tradable'] == 0) || ($descriptions['marketable'] == 0)) {
$price = 0;
$class = 'minPrice';
$text = 'Not tradable';
}
# Adding to Array
$inventory[] = [
'name' => $descriptions['market_name'],
'price' => floor($price),
'color' => $this->getRarity($descriptions['tags']),
'tradable' => $descriptions['tradable'],
'class' => $class,
'text' => $text,
'classid' => $item['classid'],
'assetid' => $item['assetid'],
'instanceid' => $item['instanceid']
];
}
}
}
}
}
Session::put('InvUPD', (time() + 5));
return [
'success' => true,
'items' => $inventory
];
}
But should return approximately the following value:
{"success":true,"items":[{"classid":"2274725521","instanceid":"57949762","assetid":"18235196074","market_hash_name":"Full-Bore Bonanza","price":26}]}
Where my mistake?
First of all, you are iterating on descriptions for every assets, which is assets*descriptions iteration, it's quite a lot, but you can optimize this.
let's loop once for descriptions and assign classid and instanceid as object key.
$assets = $response["assets"];
$descriptions = $response["descriptions"];
$newDescriptions=[];
foreach($descriptions as $d){
$newDescriptions[$d["classid"]][$d["instanceid"]] = $d;
}
this will give as the ability to not loop over description each time, we can access the description of certain asset directly $newDescriptions[$classid][$instanceid]]
foreach($assets as $a){
if(isset($newDescriptions[$a["classid"]]) && isset($newDescriptions[$a["classid"]][$a["instanceid"]])){
$assetDescription = $newDescriptions[$a["classid"]][$a["instanceid"]];
$inventory = [];
if(isset($prices[$assetDescription["market_hash_name"]])){
$price = $prices[$assetDescription['market_hash_name']]["price"]*$this->config->curs;
$class = false;
$text = false;
if($price <= $this->config->min_dep_sum) {
$price = 0;
$text = 'Cheap';
$class = 'minPrice';
}
if(($assetDescription['tradable'] == 0) || ($assetDescription['marketable'] == 0)) {
$price = 0;
$class = 'minPrice';
$text = 'Not tradable';
}
$inventory["priceFound"][] = [
'name' => $assetDescription['market_name'],
'price' => floor($price),
'color' => $this->getRarity($assetDescription['tags']),
'tradable' => $assetDescription['tradable'],
'class' => $class,
'text' => $text,
'classid' => $a['classid'],
'assetid' => $a['assetid'],
'instanceid' => $a['instanceid']
];
}else{
$inventory["priceNotFound"][] = $assetDescription["market_hash_name"];
}
}
}
About your mistake:
are you Sure your "prices.txt" contains market_hash_name?
I don't see any other issue yet, operationg on the data you have provided in comment, I got print of variable $assetDescription. Please doublecheck variable $prices.

Displaying specific array values using substr

I want to display Yes if one of the type values begins with the letter p, however I keep outputting NONO. Any help greatly appreciated...`
<?php
$pals[] = array('name' => 'jon' , 'type' => 'peach');
$pals[] = array('name' => 'gore' , 'type' => 'choc');
foreach($pals as $key => $value) {
if (substr($value['type'], 0) === "p") {
echo "Yes";
} else {
echo "NO";
}
}
Update this line :
if (substr($value['type'], 0,1) === "p") {
Try substr($value['type'],0, 1)
To make it without substr, if you want
<?php
$pals[] = array('name' => 'jon' , 'type' => 'peach');
$pals[] = array('name' => 'gore' , 'type' => 'choc');
foreach($pals as $key => $value) {
$type = trim($value["type"]);
if ($type[0] === "p") {
echo "$type : Yes\n";
} else {
echo "$type : NO";
}
}
?>
live demo : https://eval.in/754179

php readfile() and fopen() damaged/corrupt download

Long time lurker first time poster,
Im done pulling my hair out over this, so i figured i would swallow the pride and ask the experts,
I have read in excess of 20 similar issues here and tried all fixes solutions but im getting the same results.
Im using PHP for users to download items, however i have tried readfile and fopen but EVERY download is corrupt, sometimes 0 in size other times the correct(ish) size, But always damaged or corrupt
Can someone take a peek at this code and tell me whats wrong with it, ive scoured it so many times now im probably just missing something rediculously simple, ..... as usual
Any help would be greatly appreciated.
(contents of /loap.php can be shown if needed)
EDIT : Resolved
Just a quick update for anyone who stumbled across this, I managed to get this working ...... I had tried many different variations of certain commands, but it seems i had missed trying with "ob_clean()" and "ob_end_flush()" with fopen(),
.. It did the trick and as i expected it was a simple fix Thanks for the help Twisty, you poked at my inspiration ;)
<?php
require_once('../secura/load.php');
function get_remote_file_size($url, $readable = true){
$parsed = parse_url($url);
$host = $parsed["host"];
$fp = #fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp) return false;
else {
#fputs($fp, "HEAD $url HTTP/1.1\r\n");
#fputs($fp, "HOST: $host\r\n");
#fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while(!#feof($fp))$headers .= #fgets ($fp, 128);
}
#fclose ($fp);
$return = false;
$arr_headers = explode("\n", $headers);
foreach($arr_headers as $header) {
$s = "Content-Length: ";
if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
$return = trim(substr($header, strlen($s)));
break;
}
}
return $return;
}
function get_ext($name)
{
$fn = get_basename($name);
return (strpos($fn, '.') ? strtolower(substr(strrchr($fn, '.'), 1)) : '');
}
function get_basename($name)
{
return basename(str_replace('\\', '/', $name));
}
function get_filesize_unit($size)
{
$size = max(0, $size);
static $u = array(' B', 'KB', 'MB', 'GB');
for ($i=0; $size >= 1024 && $i < 4; $i++)
{
$size /= 1024;
}
return number_format($size, 1).' '.$u[$i];
}
///////////////////////////////////////////////////////////////////////////////////////////////
function find_mime_type($ext)
{
static $mime_types = array(
'application/andrew-inset' => array('ez'),
'application/mac-binhex40' => array('hqx'),
'application/mac-compactpro' => array('cpt'),
'application/mathml+xml' => array('mathml'),
'application/msword' => array('doc'),
'application/octet-stream' => array('bin', 'dms', 'lha',
'lzh', 'exe', 'class', 'so', 'dll', 'dmg'),
'application/oda' => array('oda'),
'application/ogg' => array('ogg'),
'application/pdf' => array('pdf'),
'application/postscript' => array('ai', 'eps', 'ps'),
'application/rdf+xml' => array('rdf'),
'application/smil' => array('smi', 'smil'),
'application/srgs' => array('gram'),
'application/srgs+xml' => array('grxml'),
'application/vnd.mif' => array('mif'),
'application/vnd.mozilla.xul+xml' => array('xul'),
'application/vnd.ms-excel' => array('xls'),
'application/vnd.ms-powerpoint' => array('ppt'),
'application/vnd.wap.wbxml' => array('wbxml'),
'application/vnd.wap.wmlc' => array('wmlc'),
'application/vnd.wap.wmlscriptc' => array('wmlsc'),
'application/voicexml+xml' => array('vxml'),
'application/x-bcpio' => array('bcpio'),
'application/x-cdlink' => array('vcd'),
'application/x-chess-pgn' => array('pgn'),
'application/x-cpio' => array('cpio'),
'application/x-csh' => array('csh'),
'application/x-director' => array('dcr', 'dir', 'dxr'),
'application/x-dvi' => array('dvi'),
'application/x-futuresplash' => array('spl'),
'application/x-gtar' => array('gtar'),
'application/x-hdf' => array('hdf'),
'application/x-javascript' => array('js'),
'application/x-koan' => array('skp', 'skd', 'skt', 'skm'),
'application/x-latex' => array('latex'),
'application/x-netcdf' => array('nc', 'cdf'),
'application/x-sh' => array('sh'),
'application/x-shar' => array('shar'),
'application/x-shockwave-flash' => array('swf'),
'application/x-stuffit' => array('sit'),
'application/x-sv4cpio' => array('sv4cpio'),
'application/x-sv4crc' => array('sv4crc'),
'application/x-tar' => array('tar'),
'application/x-tcl' => array('tcl'),
'application/x-tex' => array('tex'),
'application/x-texinfo' => array('texinfo', 'texi'),
'application/x-troff' => array('t', 'tr', 'roff'),
'application/x-troff-man' => array('man'),
'application/x-troff-me' => array('me'),
'application/x-troff-ms' => array('ms'),
'application/x-ustar' => array('ustar'),
'application/x-wais-source' => array('src'),
'application/xhtml+xml' => array('xhtml', 'xht'),
'application/xslt+xml' => array('xslt'),
'application/xml' => array('xml', 'xsl'),
'application/xml-dtd' => array('dtd'),
'application/zip' => array('zip'),
'audio/basic' => array('au', 'snd'),
'audio/midi' => array('mid', 'midi', 'kar'),
'audio/mpeg' => array('mpga', 'mp2', 'mp3'),
'audio/x-aiff' => array('aif', 'aiff', 'aifc'),
'audio/x-mpegurl' => array('m3u'),
'audio/x-pn-realaudio' => array('ram', 'ra'),
'application/vnd.rn-realmedia' => array('rm'),
'audio/x-wav' => array('wav'),
'chemical/x-pdb' => array('pdb'),
'chemical/x-xyz' => array('xyz'),
'image/bmp' => array('bmp'),
'image/cgm' => array('cgm'),
'image/gif' => array('gif'),
'image/ief' => array('ief'),
'image/jpeg' => array('jpeg', 'jpg', 'jpe'),
'image/png' => array('png'),
'image/svg+xml' => array('svg'),
'image/tiff' => array('tiff', 'tif'),
'image/vnd.djvu' => array('djvu', 'djv'),
'image/vnd.wap.wbmp' => array('wbmp'),
'image/x-cmu-raster' => array('ras'),
'image/x-icon' => array('ico'),
'image/x-portable-anymap' => array('pnm'),
'image/x-portable-bitmap' => array('pbm'),
'image/x-portable-graymap' => array('pgm'),
'image/x-portable-pixmap' => array('ppm'),
'image/x-rgb' => array('rgb'),
'image/x-xbitmap' => array('xbm'),
'image/x-xpixmap' => array('xpm'),
'image/x-xwindowdump' => array('xwd'),
'model/iges' => array('igs', 'iges'),
'model/mesh' => array('msh', 'mesh', 'silo'),
'model/vrml' => array('wrl', 'vrml'),
'text/calendar' => array('ics', 'ifb'),
'text/css' => array('css'),
'text/html' => array('html', 'htm'),
'text/plain' => array('asc', 'txt'),
'text/richtext' => array('rtx'),
'text/rtf' => array('rtf'),
'text/sgml' => array('sgml', 'sgm'),
'text/tab-separated-values' => array('tsv'),
'text/vnd.wap.wml' => array('wml'),
'text/vnd.wap.wmlscript' => array('wmls'),
'text/x-setext' => array('etx'),
'video/mpeg' => array('mpeg','3gp','mp4', 'mpg', 'mpe'),
'video/quicktime' => array('qt', 'mov'),
'video/vnd.mpegurl' => array('mxu', 'm4u'),
'video/x-msvideo' => array('avi'),
'video/x-sgi-movie' => array('movie'),
'x-conference/x-cooltalk' => array('ice')
);
foreach ($mime_types as $mime_type => $exts)
{
if (in_array($ext, $exts))
{
return $mime_type;
}
}
return 'text/plain';
}
$id = $_GET['id'];
$error = false;
$error = (!$product->is_product($id)?$products->error:$error);
$error =(!$purchases->is_purchased($_SESSION['uid'],$id)?$purchases->error:$error);
if(!$error){
$file = $product->details($id);
$filepath = $file['file'];
$fname=get_basename($filepath);
if (fopen($filepath,r) || (file_exists($filepath)) ){
if (#filesize($filepath)){
$fsize =filesize($filepath);
}
else
{
$fsize = get_remote_file_size($filepath);
}
$ext= get_ext($fname);
$ctype= find_mime_type($ext);
header('Content-Type:'. $ctype );
header('Content-Length: ' . $fsize);
header('Content-Disposition: attachment; filename=' . $fname);
ob_clean();
$file = fopen($filepath,'r');
ob_end_flush();
fpassthru($file);
set_time_limit(0);
}else{
return 'File Doesn\'t Exist'; } // exist fxn....
}
echo $error;
?>
Just a quick update for anyone who stumbled across this, I managed to get this working ......
I had tried many different variations of certain commands,
but it seems i had missed trying with ob_clean() and ob_end_flush() with fopen() , ..
It did the trick and as i expected it was a simple fix
Thanks for the help Twisty, you poked at my inspiration ;)
The corrected and working code has been updated in the OP
Make sure you do not have any code executed after the last line readfile(FILE_NAME)
In my case, I had to add die(); or exit(); as the last line, because MVC framework continues to render the view after readfile

Cakephp set function not passing variables from controller to the view

I'm trying to pass variable to the view and this one is very weird as the naming and directory structure is correct. Below is the function in my controller:
public function validate_apply_link(){
App::uses('CakeEmail', 'Network/Email');
$this->layout = 'blank';
$listings = $this->CareersAndJob->query("
SELECT l.sid, l.title, lp.value, u.CompanyName, u.WebSite
FROM listings l
LEFT JOIN listings_properties lp
ON lp.object_sid = l.sid
LEFT JOIN users u
ON u.sid = l.user_sid
WHERE l.active = 1
AND lp.add_parameter = 2
AND l.JobGateSenderReference IS NULL
AND u.CompanyName != 'AECOM'
ORDER BY u.CompanyName ASC
LIMIT 5
");
$doc = new DOMDocument();
ob_start();
$listing_count = count($listings);
echo nl2br("Checking $listing_count active jobs...\n\n");
$i=0;
foreach($listings as $listing){
$sid = $listing['l']['sid'];
$url = $listing['lp']['value'];
$company_name = $listing['u']['CompanyName'];
$title = htmlspecialchars($listing['l']['title']);
$length = strpos($title, "-");
if($length != 0){
$title = substr($title, 0, $length-1);
}
$title = substr($title, 0, $length-1);
$title = substr($title, 0, 10);
$data = $this->curl($url);
$check_pdf = strpos($data['info']['content_type'], "pdf");
if($check_pdf != false){
$outputs['data'][$i]['url'] = $url;
$outputs['data'][$i]['sid'] = $sid;
$outputs['data'][$i]['title'] = $title;
$outputs['data'][$i]['company_name'] = $company_name;
$outputs['data'][$i]['our_link'] = "http://careersandjobs.com.au/display-job/{$sid}";
$outputs['data'][$i]['content_type'] = $data['info']['content_type'];
$outputs['data'][$i]['data_type'] = 'pdf';
$i++;
continue;
}
#$doc->loadHTML($data['results']);
$html = $doc->saveHTML();
$xpath = new DOMXpath($doc);
$body = $doc->getElementsByTagName('body')->item(0);
$parsed_url = parse_url($url);
switch($parsed_url['host']){
case "www.michaelpage.com.au":
parse_str($url);
$exist = $xpath->query("//*[contains(#value,'{$ref}')]");
break;
case "https://vacancies.mackay.qld.gov.au":
parse_str($url);
$exist = $xpath->query("//*[contains(#value,'{$title}')]");
break;
default:
$exist = $xpath->query("//*[contains(text(),'{$title}')]");
break;
}
if($exist->length == 0){
if(strpos($url, '#') == false){
$outputs['data'][$i]['url'] = $url;
$outputs['data'][$i]['sid'] = $sid;
$outputs['data'][$i]['title'] = $title;
$outputs['data'][$i]['company_name'] = $company_name;
$outputs['data'][$i]['our_link'] = "http://careersandjobs.com.au/display-job/{$sid}";
$outputs['data'][$i]['content_type'] = $data['info']['content_type'];
$response_code = $this->http_response_codes($data['info']['http_code']);
$outputs['data'][$i]['response_code'] = $response_code;
$outputs['data'][$i]['data_type'] = 'title_not_found';
}else{
$outputs['data'][$i]['data_type'] = 'no_iframe';
}
$i++;
}
flush();
ob_flush();
}
$this->set(compact('outputs'));
}
I can do pr on the outputs variable in the view but this outputs to NULL but when I delete the entire bunch of code inside the controller function and just pass a test variable through it works.
Is there something wrong with the function that I am not aware of?
No errors were found in the above function by the way
app/Controller/CareersAndJobsController.php (line 1048)
array(
'data' => array(
(int) 0 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225055',
'sid' => '3649',
'title' => 'Graduate P',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3649',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
),
(int) 1 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225724',
'sid' => '3726',
'title' => 'Program &a',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3726',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
),
(int) 2 => array(
'url' => 'http://bawbawshire.currentjobs.com.au/cvbuilder/apply+for+this+job/no/1225826',
'sid' => '3727',
'title' => 'Road Netwo',
'company_name' => 'Baw Baw Shire Council',
'our_link' => 'http://careersandjobs.com.au/display-job/3727',
'content_type' => 'text/html; charset=utf-8',
'response_code' => 'OK',
'data_type' => 'title_not_found'
)
)
)
This is what I am getting from outputs variable just before it gets set by the set function in controller
Any reason you chose to use CakePHP? Because you seem to not make use of its functionality!
You're using literal SQL queries, therefore basically skipping the Models functionality.
You're outputting your content from your Controller? Be careful when using output buffering, this may conflict with CakePHP's inner workings, which also relies on output buffering in many cases. Because you're already outputting the content here (ob_flush()), you'll be outputting your content before your View is reached..
Normally I would point to specific points in the manual, however, because there's so much wrong here, I would suggest to start reading at the beginning

Categories