Coded on Windows, Not working on Linux - php

I'm having issues with my code on Linux, It works fine on Windows which is running PHP 7.1 and Linux is running PHP 7.0. Looking at my code it doesn't look like I am using any of the features that came in 7.1 and are not in 7.0.
If I call this method on its own it works fine, When it is used within my other code it doesn't seem to run at all.
public function titleRegex($title){
$re = "/^.+?(?=\\s*[(.]?(\\d{4}))/mi";
$str = "$title";
if(preg_match_all($re, $str, $matches) != null) {
if (!empty($matches[0])) {
$arrayString = implode('', $matches[0]);
return $arrayString;
}
}
return $title;
}
$title = pathinfo($name, PATHINFO_FILENAME);
$regexTitle = $this->titleRegex($title);
$imdbQuery = $this->imdbScraper($regexTitle);
$location = base64_encode(pathinfo($name, PATHINFO_DIRNAME));
// SQL Data is here
When I run the directoryscanner it attempts no regex, If I call the regex method on its own and pass my own values into it, It works fine. Also I have installed PHP7.0-curl and when I do a curl request on all the movie titles it returns nothing... but if I call the method on its own it works fine. I am totally lost what could be causing this.

Related

broken preg_match function ? (php 7.4.2)

I have a very strange problem.
When I open the script below in the browser and execute it, everything works as expected. Even if I call the script in the command line, I have the expected result.
But if I run the script in a background job, the script aborts in the "preg_match" function without any error. I don't have an error message for this anywhere, neither in the logs nor anywhere else. I also checked if the function exists and it does.
The script just seems to abort at preg_match and doesn't show any message about possible errors. So i'm getting only the output "CHECKPOINT 1".
I have checked the PHP versions and everywhere the same version (same path). Also the settings of pcre are identical.
Is it possible that I have different modules or functions for preg_match? Is there any way I can check what happens in the function?
with try & catch i don't get any information about the problem.
<?php
class pcre_check
{
public function setUp() {
}
public function perform() {
echo "CHECKPOINT 1";
preg_match("/[0-9]{4}/", "6876 ABCDEFGH", $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
echo "CHECKPOINT 2";
}
public function tearDown() {
}
}
$test = new pcre_check();
$test->setUp();
$test->perform();
$test->tearDown();
?>
Systeminfos:
Apache server
PHP 7.4.2
The same script works online on the production server. Only on my local server I have this problem.
It seems there is an issue with regular expressions. The function preg_replace isn't working too but str_replace with replacement of a normal string is working.
It seems that it is working now. I didn't find the problem, but after the update to macOS Big Sur it seems to work now.

Phalcon: rendering output to variable returns empty string in prod server

I have phalcon 3.4.4 installed on windows 01 with php 7.3.7 in my local machine.
i have following code
<?php
$view = $this->view;
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
$view->render("", "testtest");
$content = $view->getRender('', "testtest", array("name"=>"Mr. XYZ"), function($view)
{
$view->setRenderLevel(View::LEVEL_ACTION_VIEW);
});
echo $content;
exit;
?>
And Another way to get same output
<?php
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$content = $this->view->getRender('', "testtest", array("name"=>"Mr. XYZ"), function($view)
{
$view->setRenderLevel(View::LEVEL_LAYOUT);
});
echo $content;
exit;
?>
Both of the above code snippets works perfectly fine in my local machine.
But in production server $content returns empty string. No errors displayed and no errors in error logs. The production server is ubuntu with php 7.3.6 with phalcon 3.4.3
Can anybody help me on this what might be wrong, did I miss anything?
Thanks.

Php split and explode not working within production website

I have a split and explode function which I'm using on my website to show data but for some reason when I place the code into my production file and run it nothing comes up. The same code works perfect when I test it on a local server though...
<?php
$page = file_get_contents("https://www.ato.gov.au/tax-
professionals/prepare-and-lodge/due-dates/");
$split = explode("</span><h1>", explode("</span></Div>",
$page)[0])[1];
$split = str_replace("/tax-professionals/",
"https://www.ato.gov.au/tax-professionals/", $split);
echo $split
?>
Please check your allow_url_fopen is on in your php.ini file on production server.
You can also check it via
echo phpinfo()

Modx Evo with PHP 5.4 and eval

Got a bit of an issue with Modx and latest version of PHP.
It's a very old version of Modx (don't ask - I have exactly the same thoughts, wasn't in my control). The site is working fine on PHP 5.2.
The problem is the web host is upgrading to PHP 5.4 - as a result the site breaks completely. The one issue I can't get a solution for is the use of eval within manager/includes/document.parser.class.inc.php under "evalSnippet()" function where it calls depreciated eval() function.
I've looked at possibliity of upgrading Modx to latest which is 1.0.9, however this still uses eval() -> even though it explicity states this version supports PHP 5.4. Below is the code:
function evalSnippet($snippet, $params) {
$etomite= $modx= & $this;
$modx->event->params= & $params; // store params inside event object
if (is_array($params)) {
extract($params, EXTR_SKIP);
}
ob_start();
$snip= eval ($snippet);
$msg= ob_get_contents();
ob_end_clean();
if ((0<$this->config['error_reporting']) && isset($php_errormsg))
{
$error_info = error_get_last();
if($error_info['type']===2048 || $error_info['type']===8192) $error_type = 2;
else $error_type = 3;
if(1<$this->config['error_reporting'] || 2<$error_type)
{
extract($error_info);
if($msg===false) $msg = 'ob_get_contents() error';
$result = $this->messageQuit('PHP Parse Error', '', true, $type, $file, 'Snippet', $text, $line, $msg);
if ($this->isBackend())
{
$this->event->alert("An error occurred while loading. Please see the event log for more information<p>{$msg}{$snip}</p>");
}
}
}
unset ($modx->event->params);
return $msg . $snip;
}
Is there away around this? Has anyone managed to get Modx Evo working with PHP 5.4?
Continued from comments on original post...
session_is_registered() is deprecated as of PHP 5.3. You'll need to check through your snippets and find out which one is using this function, then replace it with isset($_SESSION['name_of_variable']).
Quickest way to find it would be to run a %LIKE% search in phpMyAdmin for session_is_registered on the modx_site_snippets table

Why is DOMDocument not working with WAMP server?

I’m using DOMDocument to retrieve several bits of text from a webpage and place them into an array. The same code works on another server, yet doesn’t on mine. I get Trying to get property of non-object for each iteration of the while loop and the array remains empty at the end.
$html = file_get_contents("http://sugarkettle.site44.com/catering.html");
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_clear_errors();
$meatPrices = array();
function fillArrayFromDOM($array,$type) {
global $doc;
$i = 0;
$label = 1;
$array = array();
while ($label <= 15):
$array[$i] = $doc->getElementById($type.$label)->textContent;
$i++;
$label++;
endwhile;
return $array;
}
fillArrayFromDOM($meatPrices,"meat");
echo var_dump($meatPrices);
Here’s a link to it working:
http://www.evintr.com/willtest.php
He’s running a GoDaddy server and I have a local WAMP (2.2) server. Any configuration options I can provide that might explain why this is happening? Or does the problem have nothing to do with my server config?
Any help much appreciated. Thanks in advance!
Update 1 - 11/16/12
On my server, I've tested $meatPrices[1] = $doc->getElementById('meat1')->textContent; and it works. For whatever reason, inside the while loop the same expression (except with variables in the getElementById parameters) tosses an error: Trying to get property of non-object.
Update 2 - 11/17/12
My WAMP server is running PHP version 5.3.13.
My friend's server is running PHP version 5.3.6.
Try with adding allow_url_fopen=on in your PHP configuration file (php.ini). Save it and restart Apache; it should work...
EDIT:
Check also if you have extension php_openssl.dll enabled (extension=php_openssl.dll in your php.ini file). Again, restart of Apache would be required.
EDIT:
It depends on PHP version you have but here are two potential solutions:
replace line fillArrayFromDOM($meatPrices,"meat"); with
$meatPrices = fillArrayFromDOM($meatPrices,"meat"); You can also
change your function to remove necessary $meatPrices parameter).
or
replace line function fillArrayFromDOM($array,$type) { with function fillArrayFromDOM(&$array,$type) { //note new character &; it will keep reference to $array variable so it could be changeable; you can also remove line: $array = array();
Both should work; I am in rush have no time to wait on your comment response. Let us know what you get...

Categories