0

I'm trying to take a value from some variable which looks like this:

$ a= '[custom:data-rekrutacji]';

using [custom:data-rekrutacji] token which I've already defined which should contain the value: 2015-08-11 13:00:00, but if I check it using var_dump() as below:

var_dump($a);

I'm getting something like this:

string(24) "
2015-08-11 13:00:00

"

However I would like to have only this (as below) so I can use function strtotime($a):

2015-08-11 13:00:00

Is it possible to trim this?

I've tried in this way, but without success:

$a= '[custom:data-rekrutacji]';
trim($a);
echo strtotime($a);
kenorb
  • 155,785
  • 88
  • 678
  • 743
Anna K
  • 1,666
  • 4
  • 23
  • 47
  • 2
    You'll have to figure out *where* the `[placeholder]` gets swapped for a datetime string. That's also where the extraneous linebreaks originate. And where they should be trimmed. – mario Aug 09 '15 at 09:35

2 Answers2

2

Have you tried saving the change:

$a = trim($a);

$a= '[custom:data-rekrutacji]';
$a = trim($a);
echo strtotime($a);

EDIT:

If your variable has the correct values it should output correctly.

$a= "    2015-08-11 13:00:00    ";
$a = trim($a);
echo "Trimmed: [".$a."]\n";
echo strtotime($a);

Code between the [ ] shows it was trimmed correctly, the next one should return the time in an int.

This is the result I get:

Trimmed: [2015-08-11 13:00:00]
1439290800
Kevin P.
  • 401
  • 4
  • 13
0

When using trim() function, remember it returns a string, not changing the existing one. So to make it work, you should do:

$a = trim($a);

instead of just:

trim($a);

As this function returns a string with whitespace stripped from the beginning and end of str.

kenorb
  • 155,785
  • 88
  • 678
  • 743