Contact form {"error":true,"message":"404 not found!"} - php
I got an error after sending contact form and the message doesn't come in my admin panel. Any ideas?
{"error":true,"message":"404 not found!"}
enter image description here
PHP version: 7.3.33
PrestaShop version: 1.7.8.8
Request URL: https://oneride.eu/en/contact-us
Request Method: POST
Status Code: 200
Request Form Data:
id_contact: 2
from: mail#mail.com
id_order: 708
fileUpload: (binary)
message: test
psgdpr_consent_checkbox: 1
url:
token: a3511a4e2dcb2717ab336e20b8ca69b3
submitMessage: Send
Debug mode //oneride.eu/en/contact-us :
(1/1) ContextErrorException
Warning: json_decode() expects parameter 1 to be string, array given
in tawkto.php line 135
at Tawkto->hookDisplayFooter(array('smarty' => object(SmartyCustomTemplate), 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 1))
in Hook.php line 1007
at HookCore::coreCallHook(object(Tawkto), 'hookDisplayFooter', array('smarty' => object(SmartyCustomTemplate), 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 1))
in Hook.php line 13
at Hook::coreCallHook(object(Tawkto), 'hookDisplayFooter', array('smarty' => object(SmartyCustomTemplate), 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 1))
in Hook.php line 431
at HookCore::callHookOn(object(Tawkto), 'displayFooter', array('smarty' => object(SmartyCustomTemplate), 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 1))
in Hook.php line 944
at HookCore::exec('displayFooter', array('smarty' => object(SmartyCustomTemplate), 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 1), null)
in smarty.config.inc.php line 167
at smartyHook(array('h' => 'displayFooter'), object(SmartyCustomTemplate))
in SmartyLazyRegister.php line 83
at SmartyLazyRegister->__call('smartyHook', array(array('h' => 'displayFooter'), object(SmartyCustomTemplate)))
in a7a56b2fa98f8bb9c3e9557be5244fafdabbb7d0_2.file.footer.tpl.php line 78
at Block_99635320563e3665eedae42_10577993->callBlock(object(SmartyCustomTemplate))
in smarty_internal_runtime_inheritance.php line 248
at Smarty_Internal_Runtime_Inheritance->callBlock(object(Block_99635320563e3665eedae42_10577993), object(SmartyCustomTemplate))
in smarty_internal_runtime_inheritance.php line 184
at Smarty_Internal_Runtime_Inheritance->process(object(SmartyCustomTemplate), object(Block_99635320563e3665eedae42_10577993))
in smarty_internal_runtime_inheritance.php line 156
at Smarty_Internal_Runtime_Inheritance->instanceBlock(object(SmartyCustomTemplate), 'Block_99635320563e3665eedae42_10577993', 'hook_footer')
in a7a56b2fa98f8bb9c3e9557be5244fafdabbb7d0_2.file.footer.tpl.php line 30
at content_63e3665eee0747_13776542(object(SmartyCustomTemplate))
in smarty_template_resource_base.php line 123
at Smarty_Template_Resource_Base->getRenderedTemplateCode(object(SmartyCustomTemplate))
in smarty_template_compiled.php line 114
at Smarty_Template_Compiled->render(object(SmartyCustomTemplate))
in smarty_internal_template.php line 216
at Smarty_Internal_Template->render()
in smarty_internal_template.php line 385
at Smarty_Internal_Template->_subTemplateRender('file:_partials/footer.tpl', null, 'at_moviclayouts/layout-left-column.tpl', 0, 31536000, array(), 0, false)
in e2edce3fe10e6aa05aff7c1599af26310b1ccbc7_2.file.layout-both-columns.tpl.php line 358
at Block_19810866863e3665eb94015_33088710->callBlock(object(SmartyCustomTemplate))
in smarty_internal_runtime_inheritance.php line 248
at Smarty_Internal_Runtime_Inheritance->callBlock(object(Block_19810866863e3665eb94015_33088710), object(SmartyCustomTemplate))
in smarty_internal_runtime_inheritance.php line 184
at Smarty_Internal_Runtime_Inheritance->process(object(SmartyCustomTemplate), object(Block_19810866863e3665eb94015_33088710))
in smarty_internal_runtime_inheritance.php line 156
at Smarty_Internal_Runtime_Inheritance->instanceBlock(object(SmartyCustomTemplate), 'Block_19810866863e3665eb94015_33088710', 'footer')
in e2edce3fe10e6aa05aff7c1599af26310b1ccbc7_2.file.layout-both-columns.tpl.php line 116
at content_63e3665eb98d98_63460293(object(SmartyCustomTemplate))
in smarty_template_resource_base.php line 123
at Smarty_Template_Resource_Base->getRenderedTemplateCode(object(SmartyCustomTemplate))
in smarty_template_compiled.php line 114
at Smarty_Template_Compiled->render(object(SmartyCustomTemplate))
in smarty_internal_template.php line 216
at Smarty_Internal_Template->render()
in smarty_internal_template.php line 385
at Smarty_Internal_Template->_subTemplateRender('layouts/layout-both-columns.tpl', null, 'at_moviclayouts/layout-left-column.tpl', 0, 31536000, array(), 2, false, null, null)
in smarty_internal_runtime_inheritance.php line 116
at Smarty_Internal_Runtime_Inheritance->endChild(object(SmartyCustomTemplate), 'layouts/layout-both-columns.tpl')
in a1098b2decf1c96dbbc1848914cf81e44e633a60_2.file.layout-left-column.tpl.php line 38
at content_63e3665eb7f348_92763673(object(SmartyCustomTemplate))
in smarty_template_resource_base.php line 123
at Smarty_Template_Resource_Base->getRenderedTemplateCode(object(SmartyCustomTemplate))
in smarty_template_compiled.php line 114
at Smarty_Template_Compiled->render(object(SmartyCustomTemplate))
in smarty_internal_template.php line 216
at Smarty_Internal_Template->render()
in smarty_internal_template.php line 385
at Smarty_Internal_Template->_subTemplateRender('layouts/layout-left-column.tpl', null, 'at_moviclayouts/layout-left-column.tpl', 0, 31536000, array(), 2, false, null, null)
in smarty_internal_runtime_inheritance.php line 116
at Smarty_Internal_Runtime_Inheritance->endChild(object(SmartyCustomTemplate), 'layouts/layout-left-column.tpl')
in e29f4ab1fe55858e6b724549e36e5445b5a2720b_2.file.page.tpl.php line 33
at content_63e3665eb76d59_43901630(object(SmartyCustomTemplate))
in smarty_template_resource_base.php line 123
at Smarty_Template_Resource_Base->getRenderedTemplateCode(object(SmartyCustomTemplate))
in smarty_template_compiled.php line 114
at Smarty_Template_Compiled->render(object(SmartyCustomTemplate))
in smarty_internal_template.php line 216
at Smarty_Internal_Template->render()
in smarty_internal_template.php line 385
at Smarty_Internal_Template->_subTemplateRender('page.tpl', null, 'at_moviclayouts/layout-left-column.tpl', 0, 31536000, array(), 2, false, null, null)
in smarty_internal_runtime_inheritance.php line 116
at Smarty_Internal_Runtime_Inheritance->endChild(object(SmartyCustomTemplate), 'page.tpl')
in df1c39e008529093e0cd15f27cf1f604eb7202df_2.file.contact.tpl.php line 50
at content_63e3665eb6b637_82232812(object(SmartyCustomTemplate))
in smarty_template_resource_base.php line 123
at Smarty_Template_Resource_Base->getRenderedTemplateCode(object(SmartyCustomTemplate))
in smarty_template_compiled.php line 114
at Smarty_Template_Compiled->render(object(SmartyCustomTemplate))
in smarty_internal_template.php line 216
at Smarty_Internal_Template->render(false, 0)
in smarty_internal_templatebase.php line 232
at Smarty_Internal_TemplateBase->_execute(object(SmartyCustomTemplate), null, 'at_moviclayouts/layout-left-column.tpl', null, 0)
in smarty_internal_templatebase.php line 116
at Smarty_Internal_TemplateBase->fetch('contact.tpl', null, 'at_moviclayouts/layout-left-column.tpl', null, false, true, false)
in SmartyCustom.php line 112
at SmartyCustomCore->fetch('contact.tpl', null, 'at_moviclayouts/layout-left-column.tpl')
in FrontController.php line 727
at FrontControllerCore->smartyOutputContent('contact.tpl')
in FrontController.php line 709
at FrontControllerCore->display()
in Controller.php line 326
at ControllerCore->run()
in Dispatcher.php line 525
at DispatcherCore->dispatch()
in index.php line 28
I updated prestashop and modules via "1-Click Upgrade" and rolled back to default templates
Related
need help for a function in php
I have to create a function which adds the numbers from 1 to 500 except the number 42 and outputs the sum. My attempt: <?php> function addieren() { $zahlen = func_get_args(); $summe = 0; foreach($zahlen as $zahl) { $summe += $zahl; } return $summe; } echo addieren(1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 256 , 257 , 258 , 259 , 260 , 261 , 262 , 263 , 264 , 265 , 266 , 267 , 268 , 269 , 270 , 271 , 272 , 273 , 274 , 275 , 276 , 277 , 278 , 279 , 280 , 281 , 282 , 283 , 284 , 285 , 286 , 287 , 288 , 289 , 290 , 291 , 292 , 293 , 294 , 295 , 296 , 297 , 298 , 299 , 300 , 301 , 302 , 303 , 304 , 305 , 306 , 307 , 308 , 309 , 310 , 311 , 312 , 313 , 314 , 315 , 316 , 317 , 318 , 319 , 320 , 321 , 322 , 323 , 324 , 325 , 326 , 327 , 328 , 329 , 330 , 331 , 332 , 333 , 334 , 335 , 336 , 337 , 338 , 339 , 340 , 341 , 342 , 343 , 344 , 345 , 346 , 347 , 348 , 349 , 350 , 351 , 352 , 353 , 354 , 355 , 356 , 357 , 358 , 359 , 360 , 361 , 362 , 363 , 364 , 365 , 366 , 367 , 368 , 369 , 370 , 371 , 372 , 373 , 374 , 375 , 376 , 377 , 378 , 379 , 380 , 381 , 382 , 383 , 384 , 385 , 386 , 387 , 388 , 389 , 390 , 391 , 392 , 393 , 394 , 395 , 396 , 397 , 398 , 399 , 400 , 401 , 402 , 403 , 404 , 405 , 406 , 407 , 408 , 409 , 410 , 411 , 412 , 413 , 414 , 415 , 416 , 417 , 418 , 419 , 420 , 421 , 422 , 423 , 424 , 425 , 426 , 427 , 428 , 429 , 430 , 431 , 432 , 433 , 434 , 435 , 436 , 437 , 438 , 439 , 440 , 441 , 442 , 443 , 444 , 445 , 446 , 447 , 448 , 449 , 450 , 451 , 452 , 453 , 454 , 455 , 456 , 457 , 458 , 459 , 460 , 461 , 462 , 463 , 464 , 465 , 466 , 467 , 468 , 469 , 470 , 471 , 472 , 473 , 474 , 475 , 476 , 477 , 478 , 479 , 480 , 481 , 482 , 483 , 484 , 485 , 486 , 487 , 488 , 489 , 490 , 491 , 492 , 493 , 494 , 495 , 496 , 497 , 498 , 499 , 500); ?>
The issue with your script is <?php> However, you can make it shorter by, using range() to create an array of all integers from 0 to 500, then array_sum() to calculate the sum, then subtract 42. echo array_sum( range(0,500) ) - 42; https://eval.in/518979
fpdf custom font works but not on any other computer
I'm generating PDF invoices using fpdf and I would like to use a custom font. I got that working by converting the font and adding it to the fpdf and it works but if I open the PDF on any other computer the font is gone the sample of converted font (OpenSans) <?php $type='TrueType'; $name='OpenSans'; $desc=array('Ascent'=>1069,'Descent'=>-293,'CapHeight'=>714,'Flags'=>32,'FontBBox'=>'[-550 -271 1204 1048]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>600); $up=-75; $ut=50; $cw=array( chr(0)=>600,chr(1)=>600,chr(2)=>600,chr(3)=>600,chr(4)=>600,chr(5)=>600,chr(6)=>600,chr(7)=>600,chr(8)=>600,chr(9)=>600,chr(10)=>600,chr(11)=>600,chr(12)=>600,chr(13)=>600,chr(14)=>600,chr(15)=>600,chr(16)=>600,chr(17)=>600,chr(18)=>600,chr(19)=>600,chr(20)=>600,chr(21)=>600, chr(22)=>600,chr(23)=>600,chr(24)=>600,chr(25)=>600,chr(26)=>600,chr(27)=>600,chr(28)=>600,chr(29)=>600,chr(30)=>600,chr(31)=>600,' '=>260,'!'=>267,'"'=>401,'#'=>646,'$'=>572,'%'=>823,'&'=>730,'\''=>221,'('=>296,')'=>296,'*'=>552,'+'=>572, ','=>245,'-'=>322,'.'=>266,'/'=>367,'0'=>572,'1'=>572,'2'=>572,'3'=>572,'4'=>572,'5'=>572,'6'=>572,'7'=>572,'8'=>572,'9'=>572,':'=>266,';'=>266,'<'=>572,'='=>572,'>'=>572,'?'=>429,'#'=>899,'A'=>633, 'B'=>648,'C'=>631,'D'=>729,'E'=>556,'F'=>516,'G'=>728,'H'=>738,'I'=>279,'J'=>267,'K'=>614,'L'=>519,'M'=>903,'N'=>754,'O'=>779,'P'=>602,'Q'=>779,'R'=>618,'S'=>549,'T'=>553,'U'=>728,'V'=>595,'W'=>926, 'X'=>577,'Y'=>560,'Z'=>571,'['=>329,'\\'=>367,']'=>329,'^'=>542,'_'=>448,'`'=>577,'a'=>556,'b'=>613,'c'=>476,'d'=>613,'e'=>561,'f'=>339,'g'=>548,'h'=>614,'i'=>253,'j'=>253,'k'=>525,'l'=>253,'m'=>930, 'n'=>614,'o'=>604,'p'=>613,'q'=>613,'r'=>408,'s'=>477,'t'=>353,'u'=>614,'v'=>501,'w'=>778,'x'=>524,'y'=>504,'z'=>468,'{'=>379,'|'=>551,'}'=>379,'~'=>572,chr(127)=>600,chr(128)=>590,chr(129)=>600,chr(130)=>245,chr(131)=>600, chr(132)=>405,chr(133)=>784,chr(134)=>502,chr(135)=>510,chr(136)=>600,chr(137)=>1202,chr(138)=>549,chr(139)=>304,chr(140)=>549,chr(141)=>553,chr(142)=>571,chr(143)=>571,chr(144)=>600,chr(145)=>170,chr(146)=>170,chr(147)=>350,chr(148)=>350,chr(149)=>376,chr(150)=>500,chr(151)=>1000,chr(152)=>600,chr(153)=>776, chr(154)=>477,chr(155)=>304,chr(156)=>477,chr(157)=>353,chr(158)=>468,chr(159)=>468,chr(160)=>260,chr(161)=>592,chr(162)=>592,chr(163)=>523,chr(164)=>572,chr(165)=>633,chr(166)=>551,chr(167)=>516,chr(168)=>577,chr(169)=>832,chr(170)=>549,chr(171)=>497,chr(172)=>572,chr(173)=>322,chr(174)=>832,chr(175)=>571, chr(176)=>428,chr(177)=>572,chr(178)=>197,chr(179)=>261,chr(180)=>577,chr(181)=>619,chr(182)=>655,chr(183)=>266,chr(184)=>227,chr(185)=>556,chr(186)=>477,chr(187)=>497,chr(188)=>519,chr(189)=>577,chr(190)=>253,chr(191)=>468,chr(192)=>618,chr(193)=>633,chr(194)=>633,chr(195)=>633,chr(196)=>633,chr(197)=>519, chr(198)=>631,chr(199)=>631,chr(200)=>631,chr(201)=>556,chr(202)=>556,chr(203)=>556,chr(204)=>556,chr(205)=>279,chr(206)=>279,chr(207)=>729,chr(208)=>722,chr(209)=>754,chr(210)=>754,chr(211)=>779,chr(212)=>779,chr(213)=>779,chr(214)=>779,chr(215)=>572,chr(216)=>618,chr(217)=>728,chr(218)=>728,chr(219)=>728, chr(220)=>728,chr(221)=>560,chr(222)=>553,chr(223)=>622,chr(224)=>408,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>253,chr(230)=>476,chr(231)=>476,chr(232)=>476,chr(233)=>561,chr(234)=>561,chr(235)=>561,chr(236)=>561,chr(237)=>253,chr(238)=>253,chr(239)=>613,chr(240)=>613,chr(241)=>614, chr(242)=>614,chr(243)=>604,chr(244)=>604,chr(245)=>604,chr(246)=>604,chr(247)=>572,chr(248)=>408,chr(249)=>614,chr(250)=>614,chr(251)=>614,chr(252)=>614,chr(253)=>504,chr(254)=>353,chr(255)=>253); $enc='cp1250'; $diff='131 /.notdef 136 /.notdef 140 /Sacute /Tcaron 143 /Zacute 152 /.notdef 156 /sacute /tcaron 159 /zacute 161 /caron /breve /Lslash 165 /Aogonek 170 /Scedilla 175 /Zdotaccent 178 /ogonek /lslash 185 /aogonek /scedilla 188 /Lcaron /hungarumlaut /lcaron /zdotaccent /Racute 195 /Abreve 197 /Lacute /Cacute 200 /Ccaron 202 /Eogonek 204 /Ecaron 207 /Dcaron /Dcroat /Nacute /Ncaron 213 /Ohungarumlaut 216 /Rcaron /Uring 219 /Uhungarumlaut 222 /Tcedilla 224 /racute 227 /abreve 229 /lacute /cacute 232 /ccaron 234 /eogonek 236 /ecaron 239 /dcaron /dcroat /nacute /ncaron 245 /ohungarumlaut 248 /rcaron /uring 251 /uhungarumlaut 254 /tcedilla /dotaccent'; $originalsize=217360; ?>
php warning -Invalid argument supplied for foreach()
i installed a project edusec school management system which work on php mysql yii framework.but when we copy it root directory and run index.php on local server it give following error ? what i do ??please help me? PHP warning Invalid argument supplied for foreach() C:\xampp\htdocs\yiitest\protected\yii\framework\collections\CMap.php(288) 276 * #param array $b array to be merged from. You can specifiy additional 277 * arrays via third argument, fourth argument etc. 278 * #return array the merged array (the original arrays are not changed.) 279 * #see mergeWith 280 */ 281 public static function mergeArray($a,$b) 282 { 283 $args=func_get_args(); 284 $res=array_shift($args); 285 while(!empty($args)) 286 { 287 $next=array_shift($args); 288 foreach($next as $k => $v) 289 { 290 if(is_integer($k)) 291 isset($res[$k]) ? $res[]=$v : $res[$k]=$v; 292 else if(is_array($v) && isset($res[$k]) && is_array($res[$k])) 293 $res[$k]=self::mergeArray($res[$k],$v); 294 else 295 $res[$k]=$v; 296 } 297 } 298 return $res; 299 } 300 Stack Trace #0 – C:\xampp\htdocs\yiitest\protected\yii\framework\base\CModule.php(468): CMap::mergeArray(array("class" => "CDbConnection"), 1) 463 foreach($components as $id=>$component) 464 { 465 if($component instanceof IApplicationComponent) 466 $this->setComponent($id,$component); 467 else if(isset($this->_componentConfig[$id]) && $merge) 468 $this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component); 469 else 470 $this->_componentConfig[$id]=$component; 471 } 472 } 473 #1 + C:\xampp\htdocs\yiitest\protected\yii\framework\base\CComponent.php(153): CModule->setComponents(array("user" => array("allowAutoLogin" => true, "class" => "RWebUser"), "phpThumb" => array("class" => "ext.EPhpThumb.EPhpThumb"), "authManager" => array("class" => "RDbAuthManager"), "urlManager" => array("urlFormat" => "path", "rules" => array("<controller:\w+>/<id:\d+>" => "<controller>/view", "<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>", "<controller:\w+>/<action:\w+>" => "<controller>/<action>")), ...)) #2 + C:\xampp\htdocs\yiitest\protected\yii\framework\base\CModule.php(483): CComponent->__set("components", array("user" => array("allowAutoLogin" => true, "class" => "RWebUser"), "phpThumb" => array("class" => "ext.EPhpThumb.EPhpThumb"), "authManager" => array("class" => "RDbAuthManager"), "urlManager" => array("urlFormat" => "path", "rules" => array("<controller:\w+>/<id:\d+>" => "<controller>/view", "<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>", "<controller:\w+>/<action:\w+>" => "<controller>/<action>")), ...)) #3 + C:\xampp\htdocs\yiitest\protected\yii\framework\base\CApplication.php(144): CModule->configure(array("name" => "College Management System", "preload" => array("log"), "import" => array("application.models.*", "application.extensions.jtogglecolumn.*", "application.extensions.AjaxList.AjaxList", "application.components.*", ...), "modules" => array("gii" => array("class" => "system.gii.GiiModule", "password" => "secure", "generatorPaths" => array("ext.gii-extended"), "ipFilters" => array("127.0.0.1", "::1", "192.168.0.163")), 0 => "notification", 1 => "webservice", "rights" => array("install" => false, "superuserName" => "SuperAdmin", "authenticatedName" => "Authenticated", "userIdColumn" => "user_id", ...), ...), ...)) #4 + C:\xampp\htdocs\yiitest\protected\yii\framework\YiiBase.php(127): CApplication->__construct("C:\xampp\htdocs\yiitest/protected/config/main.php") #5 + C:\xampp\htdocs\yiitest\protected\yii\framework\YiiBase.php(100): YiiBase::createApplication("CWebApplication", "C:\xampp\htdocs\yiitest/protected/config/main.php") #6 – C:\xampp\htdocs\yiitest\index.php(18): YiiBase::createWebApplication("C:\xampp\htdocs\yiitest/protected/config/main.php") 13 14 // specify how many levels of call stack should be shown in each log message 15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 16 17 require_once($yii); 18 Yii::createWebApplication($config)->run(); 19 ?> 20
The function array_shift() at line 287 has returned null, so $next is not an array. And of course foreach() requires an array.
Validate the value before passing into the loop. This will catch when the array is empty. $next=array_shift($args); if ($next != null) { foreach($next as $k => $v) { // do things here } }
Finding and removing outliers in PHP
Suppose I sample a selection of database records that return the following numbers: 20.50, 80.30, 70.95, 15.25, 99.97, 85.56, 69.77 Is there an algorithm that can be efficiently implemented in PHP to find the outliers (if there are any) from an array of floats based on how far they deviate from the mean?
Ok let's assume you have your data points in an array like so: <?php $dataset = array(20.50, 80.30, 70.95, 15.25, 99.97, 85.56, 69.77); ?> Then you can use the following function (see comments for what is happening) to remove all numbers that fall outside of the mean +/- the standard deviation times a magnitude you set (defaults to 1): <?php function remove_outliers($dataset, $magnitude = 1) { $count = count($dataset); $mean = array_sum($dataset) / $count; // Calculate the mean $deviation = sqrt(array_sum(array_map("sd_square", $dataset, array_fill(0, $count, $mean))) / $count) * $magnitude; // Calculate standard deviation and times by magnitude return array_filter($dataset, function($x) use ($mean, $deviation) { return ($x <= $mean + $deviation && $x >= $mean - $deviation); }); // Return filtered array of values that lie within $mean +- $deviation. } function sd_square($x, $mean) { return pow($x - $mean, 2); } ?> For your example this function returns the following with a magnitude of 1: Array ( [1] => 80.3 [2] => 70.95 [5] => 85.56 [6] => 69.77 )
For a normally distributed set of data, removes values more than 3 standard deviations from the mean. <?php function remove_outliers($array) { if(count($array) == 0) { return $array; } $ret = array(); $mean = array_sum($array)/count($array); $stddev = stats_standard_deviation($array); $outlier = 3 * $stddev; foreach($array as $a) { if(!abs($a - $mean) > $outlier) { $ret[] = $a; } } return $ret; }
Topic: Detecting local, additive outliers in unordered arrays by walking a small window through the array and calculating the standard deviation for a certain range of values. Good morning folks, here is my solution much to late, but since I was looking for detecting outliers via PHP and could'nt find anything basic, I decided somehow smoothing a given dataset in a timeline of 24 h by simply moving a range of 5 items in a row through an unordered array and calculate the local standard deviation to detect the additive outliers. The first function will simply calculate the average and deviation of a given array, where $col means the column with the values (sorry for the freegrades, this means that in an uncomplete dataset of 5 values you only have 4 freegrades - I don't know the exact english word for Freiheitsgrade): function analytics_stat ($arr,$col,$freegrades = 0) { // calculate average called mu $mu = 0; foreach ($arr as $row) { $mu += $row[$col]; } $mu = $mu / count($arr); // calculate empiric standard deviation called sigma $sigma = 0; foreach ($arr as $row) { $sigma += pow(($mu - $row[$col]),2); } $sigma = sqrt($sigma / (count($arr) - $freegrades)); return [$mu,$sigma]; } Now its time for the core function, which will move through the given array and create a new array with the result. Margin means the factor to multiply the deviation with, since only one Sigma detects to many outliers, whereas more than 1.7 seems to high: function analytics_detect_local_outliers ($arr,$col,$range,$margin = 1.0) { $count = count($arr); if ($count < $range) return false; // the initial state of each value is NOT OUTLIER $arr_result = []; for ($i = 0;$i < $count;$i++) { $arr_result[$i] = false; } $max = $count - $range + 1; for ($i = 0;$i < $max;$i++) { // calculate mu and sigma for current interval // remember that 5 values will determine the divisor 4 for sigma // since we only look at a part of the hole data set $stat = analytics_stat(array_slice($arr,$i,$range),$col,1); // a value in this interval counts, if it's found outside our defined sigma interval $range_max = $i + $range; for ($j = $i;$j < $range_max;$j++) { if (abs($arr[$j][$col] - $stat[0]) > $margin * $stat[1]) { $arr_result[$j] = true; // this would be the place to add a counter to isolate // real outliers from sudden steps in our data set } } } return $arr_result; } And finally comes the test function with random values in an array with length 24. As for margin I was curious and choose the Golden Cut PHI = 1.618 ... since I really like this number and some Excel test results have led me to a margin of 1.7, above which outliers very rarelly were detected. The range of 5 is variable, but for me this was enough. So for every 5 values in a row there will be a calculation: function test_outliers () { // create 2 dimensional data array with items [hour,value] $arr = []; for ($i = 0;$i < 24;$i++) { $arr[$i] = [$i,rand(0,500)]; } // set parameter for detection algorithm $result = []; $col = 1; $range = 5; $margin = 1.618; $result = analytics_detect_local_outliers ($arr,$col,$range,$margin); // display results echo "<p style='font-size:8pt;'>"; for ($i = 0;$i < 24;$i++) { if ($result[$i]) echo "♦".$arr[$i][1]."♦ "; else echo $arr[$i][1]." "; } echo "</p>"; } After 20 calls of the test function I got these results: 417 140 372 131 449 26 192 222 320 349 94 147 201 ♦342♦ 123 16 15 ♦490♦ 78 190 ♦434♦ 27 3 276 379 440 198 135 22 461 208 376 286 ♦73♦ 331 358 341 14 112 190 110 266 350 232 265 ♦63♦ 90 94 228 ♦392♦ 130 134 170 ♦485♦ 17 463 13 326 47 439 430 151 268 172 342 445 477 ♦21♦ 421 440 219 95 88 121 292 255 ♦16♦ 223 244 109 127 231 370 16 93 379 218 87 ♦335♦ 150 84 181 25 280 15 406 85 252 310 122 188 302 ♦13♦ 439 254 414 423 216 456 321 85 61 215 7 297 337 204 210 106 149 345 411 308 360 308 346 ♦451♦ ♦77♦ 16 498 331 160 142 102 ♦496♦ 220 107 143 ♦241♦ 113 82 355 114 452 490 222 412 94 2 ♦480♦ 181 149 41 110 220 ♦477♦ 278 349 73 186 135 181 ♦39♦ 136 284 340 165 438 147 311 246 449 396 328 330 280 453 374 214 289 489 185 445 86 426 246 319 ♦30♦ 436 290 384 232 442 302 ♦436♦ 50 114 15 21 93 ♦376♦ 416 439 ♦222♦ 398 237 234 44 102 464 204 421 161 330 396 461 498 320 105 22 281 168 381 216 435 360 19 ♦402♦ 131 128 66 187 291 459 319 433 86 84 325 247 440 491 381 491 ♦22♦ 412 33 273 256 331 79 452 314 485 66 138 116 356 290 190 336 178 298 218 394 439 387 ♦80♦ 463 369 ♦104♦ 388 465 455 ♦246♦ 499 70 431 360 ♦22♦ 203 280 241 319 ♦34♦ 238 439 497 485 289 249 ♦416♦ 228 166 217 186 184 ♦356♦ 142 166 26 91 70 ♦466♦ 177 357 298 443 307 387 373 209 338 166 90 122 442 429 499 293 ♦41♦ 159 395 79 307 91 325 91 162 211 85 189 278 251 224 481 77 196 37 326 230 281 ♦73♦ 334 159 490 127 365 37 57 246 26 285 468 228 181 74 ♦455♦ 119 435 328 3 216 149 217 348 65 433 164 473 465 145 341 112 462 396 168 251 351 43 320 123 181 198 216 213 249 219 ♦29♦ 255 100 216 181 233 33 47 344 383 ♦94♦ 323 440 187 79 403 139 382 37 395 366 450 263 160 290 ♦126♦ 304 307 335 396 458 195 171 493 270 434 222 401 38 383 158 355 311 150 402 339 382 97 125 88 300 332 250 ♦86♦ 362 214 448 67 114 ♦354♦ 140 16 ♦354♦ 109 0 168 127 89 450 5 232 155 159 264 214 ♦416♦ 51 429 372 230 298 232 251 207 ♦322♦ 160 148 206 293 446 111 338 I hope, this will help anyone in the present or future. Greetings P.S. To further improve this algorithm you may add a counter, which makes sure, that a certain value must for instance be found at least 2 times, that means in 2 different intervals or windows, before it is labeled as outlier. So a sudden jump of the following values does not make the first value the villain. Let me give you an example: In 3,6,5,9,37,40,42,51,98,39,33,45 there is an obvious step from 9 to 37 and an isolated value 98. I would like to detect 98, but not 9 or 37. The first interval 3,6,5,9,37 would detect 37, the second interval 6,5,9,37,40 not. So we would not detect 37, since there is only one problematic interval or one match. Now it should be clear, that 98 counts in 5 intervals and is therefore an outlier. So lets declare a value an outlier, if it "counts" at least 2 times. Like so often we have to look closely the borders, since they have only one interval, and make for these values an exception.
PHP: echoing a few selected lines of a txt file
I need to echo only selected lines from a .txt file using PHP. The txt file content looks like this: 1 111 111 111 111 111 111 111 111 111 111 2 196 182 227 190 195 196 278 197 323 265 3 84.1 84.1 84.1 84.2 85.4 84.1 84.2 84.1 84.1 84.1 4 107 107 107 107 107 107 107 107 107 107 5 10.0 9.29 9.86 9.90 9.57 9.56 9.52 9.55 10.0 9.62 6 0.652 0.622 0.676 0.617 0.637 0.617 0.563 0.601 0.586 0.601 7 132 132 132 132 132 132 481 132 132 132 8 113 113 113 113 113 113 113 113 113 113 9 510 571 604 670 647 667 656 257 264 431 10 245 246 247 246 246 245 247 246 247 247 The previous working code was echoing every lines. $fp = fopen("http://xxx/myfile.txt","r"); while (!feof($fp)) { $page .= fgets($fp, 4096); } fclose($fp); echo $page; break; I'm trying to get the same formating but only with the selected lines. For instance let say only lines: 3, 5, 8, 10. The second step would then be if the lines could be echoed in a different order than the initial one. If someone knows a simple way to do it, that would be excellent! Thanx in advance.
$lines = file('http://xxx/myfile.txt'); print $lines[2]; // line 3 print $lines[4]; // line 5 ... see file()
here's an example of how it can be done: function echo_selected_lines_of_file($file, array $lines) { $fContents = file_get_contents($file); // read the file $fLines = explode("\n", $fContents); // split the lines foreach($fLines as $key=>$fLine) // foreach line... if(in_array($key, $lines)) //if its in the $lines array, print it echo $fLine.'<br>'; } echo_selected_lines_of_file('index.php', array(1,4,7));
You could use the file() which converts each line into a array. But if your file is big it will consume a bit of memory. $lines_to_print = [1,3,5,8]; $lines = file('file.txt'); for($i in $line_to_print) { echo $lines[$i]; } An efficient solution is $i = 0; $lines_to_print = [1,3,5,8]; $file = fopen("file.txt", "r"); while(!feof($file)){ $line = fgets($file); if(in_array(++$i, $lines_to_print)) { echo $line } } fclose($file);