it shows"-- Debug: Undefined variable: wordscut on line 168 of /wp-content/theme"
function cutstr($string, $length) {
$string =strip_tags($string);
preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|
[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $info);
for($i=0; $i<count($info[0]); $i++) {
$wordscut.= $info[0][$i];
$j= ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
if ($j > $length - 3) {
return $wordscut." ...";
}
}
return join('', $info[0]);
}
the above is my function. i know in php, it's right if a variable doesn't be declared before it is used.why it shows"Undefined variable: wordscut, j..... thank you.
2,* REQUIRED: Non-printable characters were found in the '''functions.php''' file. You may want to check this file for errors.
what is Non-printable characters .how to correct it? thank you.
This is one one classic bug.
When PHP started your script, $wordscut is not defined. When you run
$wordscut .= "sometext";
The code actually do
$wordscut = $wordscut . "sometext";
At this point, $wordscut is not available, thus Undefined Variable error occurred.
To fix it, add
$wordscut = '';
before
for($i=0; $i<count($info[0]); $i++) {
Related
OS: FreeBSD-11.1
Name: amavisd-new-2.11.0_2,1
We recently began getting these errors from amavisd reported in our maillog:
. . .
proxy-reject: END-OF-MESSAGE: 451 4.5.0 Error in processing,
id=29937-07, quar+notif FAILED:
mail_dispatch: no recognized protocol name: -2
at /usr/local/sbin/amavisd line 9638.;
. . .
Each one of these errors results from processing messages from a single domain. However, not all of the traffic from that domain generates an error.
The code section in amavisd referred to in the message reads:
9619 my $any_deliveries = 0;
9620 my $per_recip_data = $msginfo->per_recip_data;
9621 my $num_recips_notdone =
9622 scalar(grep(!$_->recip_done && (!$filter || &$filter($_)),
9623 #$per_recip_data));
9624 while ($num_recips_notdone > 0) {
9625 # a delivery method may be a scalar of a form protocol:socket_specs, or
9626 # a listref of such elements; if a list is provided, it is expected that
9627 # each entry will be using the same protocol name, otherwise behaviour
9628 # is unspecified - so just obtain the protocol name from the first entry
9629 #
9630 my(%protocols, $any_tempfail);
9631 for my $r (#$per_recip_data) {
9632 if (!$dsn_per_recip_capable) {
9633 my $recip_smtp_response = $r->recip_smtp_response; # any 4xx code ?
9634 if (defined($recip_smtp_response) && $recip_smtp_response =~ /^4/) {
9635 $any_tempfail = $recip_smtp_response . ' (' . $r->recip_addr . ')';
9636 }
9637 }
9638 if (!$r->recip_done && (!$filter || &$filter($r))) {
9639 my $proto_sockname = $r->delivery_method;
9640 defined $proto_sockname
9641 or die "mail_dispatch: undefined delivery_method";
9642 !ref $proto_sockname || ref $proto_sockname eq 'ARRAY'
9643 or die "mail_dispatch: not a scalar or array ref: $proto_sockname";
9644 for (ref $proto_sockname ? #$proto_sockname : $proto_sockname) {
9645 local($1);
9646 if (/^([a-z][a-z0-9.+-]*):/si) { $protocols{lc($1)} = 1 }
9647 else { die "mail_dispatch: no recognized protocol name: $_" }
9648 }
9649 }
9650 }
But I have no idea where the protocol name sought is obtained. Because of the error the offending message is not placed in the quarantine folder so I cannot examine it.
Is this a configuration error on our part or is this the result of a malformed email transmission? In either case, what can I do to resolve this matter?
I am new in PHPUnit and i am required to run the test using browser and save the result in xml format.
But every time when i run this code, i got following error:
FatalErrorException: Error: Interface 'PHPUnit_Framework_Test' not found in /usr/share/php/PHPUnit/Framework/TestSuite.php line 83
My code looks like this:
require_once '/var/www/Drillsight/app/autoload.php';
require_once "PHPUnit/Framework/TestSuite.php";
require_once "PHPUnit/TextUI/TestRunner.php";
$run_command = new PHPUnit_TextUI_Command;
$run_command ->run(array('phpunit', '--log-junit', 'results.xml', 'MyPHPUnitTest.php'),true);
Can anybody help in this matter?
Any other recommendation options will be highly appreciated !
Thanks in advance !
Do it really need to be runned in a browser?
I personally use a .bat file containing all my unit test like this
REM GEM_MECHANIC_TESTS
ECHO.
ECHO FILE : GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
CALL PHPUNIT %~DP0/../../../GENERAL_CONTROLER/TEST/GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
ECHO.
REM GEM_MECHANIC_INTERFACE_BUILDER_TESTS
ECHO.
ECHO FILE : HTML_GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
CALL PHPUNIT %~DP0/../../../GENERAL_CONTROLER/TEST/TEST_INTERFACE_BUILDER/HTML_GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
ECHO.
And run a command like this in my Xampp console:
C:\xampp\htdocs\PC_administration_interface\Controler/script/temp_unit_test.bat >C:\xampp\htdocs\PC_administration_interface\Controler/test_result.txt
Or if you want to do it automatically each night with a windows task:
Launch_xampp.bat
#echo off
tasklist | find /i "xampp-control.exe" && goto :eof
start /b "xampp-control.exe" "C:\xampp\xampp-control.exe"
launch_automatic_test.bat
#echo off
call %~DP0\launch_xampp.bat
call %~DP0\..\..\..\..\xampp_shell.bat
cls
call %~DP0\run_unit_test.bat > "%~DP0\..\test_result.txt"
The method don't matter as much as I export the result in a textfile and than use PHP to parse the output (you can just change the code a bit to produce XML).
public static function fetchTestResult(&$errorMessage){
$echoString = '';
$failure = false;
$fileContent = '';
$errorMessage = '';
$dbManager = GeneralDbManager::getInstance();
if (file_exists(realpath(dirname(__FILE__)) . '/test_result.txt')) {
#$fileContent = file(realpath(dirname(__FILE__)) . '/test_result.txt');
if ($fileContent === false){
$errorMessage = $dbManager->getErrorMessage('UNIT_TEST_RESULT_LOG_ERR', "An error happened while reading the unit tests results log.");
}
else{
unlink(realpath(dirname(__FILE__)) . '/test_result.txt');
if (file_exists(realpath(dirname(__FILE__)) . '/script/temp_unit_test.bat')) {
unlink(realpath(dirname(__FILE__)) . '/script/temp_unit_test.bat');
}
$echoString = HtmlTagBuilder::createCustomTextArea("TA_UNIT_TEST_RESULT", TextAlign::ALIGN_LEFT, false, 1100, 500);
foreach ($fileContent as $line){
if (StringManager::stringStartWith($line, "FILE :")){
$failure = false;
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::TITLE_LINE);
}
elseif (StringManager::stringStartWith($line, "time:")){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::WARNING_LINE);
}
elseif (StringManager::stringStartWith($line, "OK (")){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::SUCCESS_LINE);
}
elseif ((StringManager::stringStartWith($line, "There ") and strpos($line, "failure") !== false)
or $failure === true){
$failure = true;
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::ERROR_LINE);
}
elseif (strpos(strtolower($line), "failure") !== false){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::ERROR_LINE);
}
else{
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::REGULAR_LINE);
}
}
$echoString .= '</DIV><br><br>';
}
}
else{
$errorMessage = $dbManager->getErrorMessage('UNIT_TEST_NO_RESULT_LOG_ERR', "You must run the unit test and generate the test log before displaying it.");
}
return $echoString;
}
I'm new to PHPUnit. I'm developing on an existing system, adding new features. I want to use PHPUnit to test codes I made. However, the system runs only on server (CGI) environment (access from a browser), and everything breaks while running from command-line.
Is it possible to setting PHPUnit to make a test suite which can be invoked from web browser?
Personally, I'm using windows task manager (cron can do the same thing on linux) to generate my unit test and send it to a text file every night.
Instead of display it directly in the web browser like I do, you could parse the result file directly on your server and then send the html output by email. So you could simply examine the result page on your local machine every morning like I do. Here's some code to start up your solution (on windows/PHP).
In task manager:
Action 1: C:\xampp\htdocs\PC_administration_interface\Controler\Script\launch_automatic_test.bat
Action 2: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Argument action 2: http://localhost/PC_administration_interface/view/unit_test.php?DISPLAY_RESULT=TRUE
Launch_automatic_test.bat
#echo off
call %~DP0\launch_xampp.bat
call %~DP0\..\..\..\..\xampp_shell.bat
cls
call %~DP0\run_unit_test.bat > "%~DP0\..\test_result.txt"
launch_xampp_bat
#echo off
tasklist | find /i "xampp-control.exe" && goto :eof
start /b "xampp-control.exe" "C:\xampp\xampp-control.exe"
And here's a sample of run_unit_tets.bat
#ECHO OFF
CLS
REM GEM_MECHANIC_TESTS
ECHO.
ECHO FILE : GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
CALL PHPUNIT %~DP0/../../../GEM_MECHANIC/CONTROLER/TEST/GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
ECHO.
REM GEM_MECHANIC_INTERFACE_BUILDER_TESTS
ECHO.
ECHO FILE : HTML_GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
CALL PHPUNIT %~DP0/../../../GEM_MECHANIC/CONTROLER/TEST/TEST_INTERFACE_BUILDER/HTML_GEM_MECHANIC_MANAGER_TEST.PHP
ECHO.
ECHO.
Then I'm launching a web page that parse my result and display it in the web browser:
public static function fetchTestResult(&$errorMessage){
$echoString = '';
$failure = false;
$fileContent = '';
$errorMessage = '';
$dbManager = GeneralDbManager::getInstance();
if (file_exists(realpath(dirname(__FILE__)) . '/test_result.txt')) {
#$fileContent = file(realpath(dirname(__FILE__)) . '/test_result.txt');
if ($fileContent === false){
$errorMessage = $dbManager->getErrorMessage('UNIT_TEST_RESULT_LOG_ERR', "An error happened while reading the unit tests results log.");
}
else{
unlink(realpath(dirname(__FILE__)) . '/test_result.txt');
if (file_exists(realpath(dirname(__FILE__)) . '/script/temp_unit_test.bat')) {
unlink(realpath(dirname(__FILE__)) . '/script/temp_unit_test.bat');
}
$echoString = HtmlTagBuilder::createCustomTextArea("TA_UNIT_TEST_RESULT", TextAlign::ALIGN_LEFT, false, 1100, 500);
foreach ($fileContent as $line){
if (StringManager::stringStartWith($line, "FILE :")){
$failure = false;
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::TITLE_LINE);
}
elseif (StringManager::stringStartWith($line, "time:")){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::WARNING_LINE);
}
elseif (StringManager::stringStartWith($line, "OK (")){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::SUCCESS_LINE);
}
elseif ((StringManager::stringStartWith($line, "There ") and strpos($line, "failure") !== false)
or $failure === true){
$failure = true;
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::ERROR_LINE);
}
elseif (strpos(strtolower($line), "failure") !== false){
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::ERROR_LINE);
}
else{
$echoString .= HtmlTagBuilder::addLineCustomTextArea($line, CustomTextAreaLine::REGULAR_LINE);
}
}
$echoString .= '</DIV><br><br>';
}
}
else{
$errorMessage = $dbManager->getErrorMessage('UNIT_TEST_NO_RESULT_LOG_ERR', "You must run the unit test and generate the test log before displaying it.");
}
return $echoString;
}
Additional note: I'm currently getting some information about CGI and it seem that it is pretty inefficient. You might also consider take a look at this post (question and answers):
What is Common Gateway Interface (CGI)?
I have been working on a powershell script that uses a .txt file to download multiple files from tinyurls. I have been successful in using Jobs to make this happen simultaneously, thanks to those on this forum.
The project requires some pretty large files to be downloaded, and using the current method has no progress indicator. I figured some users might think the program died. Looking for a way give a status of where it is in the download. Here is what I came up with, but I'm lost in how to pipe this information back out to the console. Any suggestions?
#Checks to see if NT-Download folder is on the Desktop, if not found, creates it
$DOCDIR = [Environment]::GetFolderPath("Desktop")
$TARGETDIR = "$DOCDIR\NT-Download"
if(!(Test-Path -Path $TARGETDIR )){
New-Item -ItemType directory -Path $TARGETDIR
}
$filepaths = Resolve-Path "files.txt"
Get-Content "$filepaths" | Foreach {
Start-Job {
function Save-TinyUrlFile
{
PARAM (
$TinyUrl,
$DestinationFolder
)
$response = Invoke-WebRequest -Uri $TinyUrl
$filename = [System.IO.Path]::GetFileName($response.BaseResponse.ResponseUri.OriginalString)
$filepath = [System.IO.Path]::Combine($DestinationFolder, $filename)
$totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
$responseStream = $response.GetResponseStream()
$buffer = new-object byte[] 10KB
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $count
try
{
$filestream = [System.IO.File]::Create($filepath)
$response.RawContentStream.WriteTo($filestream)
$filestream.Close()
while ($count -gt 0)
{
[System.Console]::CursorLeft = 0
[System.Console]::Write("Downloaded {0}K of {1}K", [System.Math]::Floor($downloadedBytes/1024), $totalLength)
$targetStream.Write($buffer, 0, $count)
$count = $responseStream.Read($buffer,0,$buffer.length)
$downloadedBytes = $downloadedBytes + $count
}
"`nFinished Download"
$targetStream.Flush()
$targetStream.Close()
$targetStream.Dispose()
$responseStream.Dispose()
}
finally
{
if ($filestream)
{
$filestream.Dispose();
}
}
}
Save-TinyUrlFile -TinyUrl $args[0] -DestinationFolder $args[1]
} -ArgumentList $_, "$TARGETDIR"
}
Have a look at Write-Progress
PS C:> for ($i = 1; $i -le 100; $i++ )
{write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i;}
Far more simple way : rely on Bits:
Start-BitsTransfer -Source $tinyUrl
I want to get the file size of an attachment of my wordpress post.
But when I run the site, I get this error ...
Can anyone help me?
"Warning: filesize(): stat failed for http://XXX.de/webdev/wp-content/uploads/2013/03/example.zip in C:\Users\XXX\Desktop\XAMPP\htdocs\webdev\wp-content\themes\web dev-theme\modul-page.php on line 27"
<?php
$a = filesize($img['url']);
echo$a;
?>
Thanks!
First check and see if the files/dirs are read/writeable.
I would do this inside of a file exist just for best practices. It is hard to determine what is wrong because you have not specified what line 27 is.
if ( file_exists($img['url']) ) {
$the_file_size = filesize($img['url']);
if ( $the_file_size >= 0 ) {
echo $the_file_size . ' bytes';
} else {
echo "File size could not be determined";
}
}