The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 807 - File: showthread.php PHP 7.3.15 (Linux)
File Line Function
/showthread.php 807 errorHandler->error





Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP logic not working
2014-06-20, 09:02 (This post was last modified: 2014-06-20 09:08 by jhonny.)
Post: #1
PHP logic not working
Hi Guys,

I'm trying to get iPXE working with PHP and MYQSL.

For some reason the PHP logic does not seem to be working.

I've got the following code in a php file that ipxe chain boots:
What its supposed to do is grab the serial number of the server and assign it to the variable: serversn
Code:
<?php
header("Content-type: text/plain");
echo "#!ipxe\n\n";

$serversn = "\${serial}";

The problem is when i then do:

Code:
echo $serversn;

The output will look something like this:

Code:
ABCDEFG

So the output is 7 alpha numeric characters long

however when i run:

Code:
echo strlen($serversn);

The output is equal to 9 !!!! instead of 7 !!!!

No idea why that is, so i tried to add some padding on either side of the $serversn variable by doing the following:

Code:
echo str_pad($serversn, 9, "X", STR_PAD_RIGHT);
echo $serversn;

The output should be: ABCDEFGXX
The output is still the original 7 alphanumeric characters: ABCDEF
Its only until that i change the str_pad parameter to 10 that one X will show up:

Code:
echo str_pad($serversn, 10, "X", STR_PAD_RIGHT);
echo $serversn;
OUTPUT is: ABCDEFGX

Can anyone advise what the heck is going on ? why is the count incorrect ?
I've also tried doing the following:

Code:
$serversn = substr($serversn,0,7);

That should cut the string contents of the $serversn variable to the first 7 characters.
Instead what happens is when i echo out $serversn, it returns the following:

Code:
${seria

The output is 7 characters long but the "value" of the variable is lost.

What is going on here ?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PHP logic not working - jhonny - 2014-06-20 09:02
RE: PHP logic not working - jhonny - 2014-06-20, 12:01



User(s) browsing this thread: 1 Guest(s)