0

The following array when printed shows that the value of $career[2] is 2010-.

However no matter what I try, this if equation will not trigger. Can these array variables be different in some way?

echo $career[2];

    if($career[2] == "2010-"){
        $career = $career[1];
    } 

A print_r of the array $career reveals this..

 Array ( 
[0] => BIS career 
[1] => CEO of the corp 
[2] => 2010- 
[3] => Leader of R&D 
[4] => 2005-10 
);

VAR DUMP

    array(11) { 
[0]=> string(316) "BIS career " 
[1]=> string(194) " CEO of the corp " 
[2]=> string(163) " 2010- " 
[3]=> string(160) " Leader of R&D " 
[4]=> string(165) " 2005-10 " }
6
  • what you want to do with your peace of code can you tell? Commented May 15, 2015 at 14:46
  • 3
    Instead of print_r() try var_dump() It might be possible that it contains space 2010- .OR Try if(trim($career[2]) == "2010-") Commented May 15, 2015 at 14:46
  • Maybe a whitespace at the end of the string... Commented May 15, 2015 at 14:49
  • Var Dump is giving me this... string(31) " 2010- " Trim does not seam to fix it. Commented May 15, 2015 at 14:56
  • Can you post your actual array var_dumped Commented May 15, 2015 at 14:57

1 Answer 1

1

You can also do:

echo "...".$career[2]."...";

it will reflect the space

Try:

preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str);

reference: Trim unicode whitespace in PHP 5.2

Sign up to request clarification or add additional context in comments.

4 Comments

Var Dump is giving me this... string(31) " 2010- " Trim does not seam to fix it.
as taken from: stackoverflow.com/questions/4166896/…, try: preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u','',$str);
Robin its hard to do with looking into the actual string, can you try sandbox.onlinephpfunctions.com and share it, also try: strpos to search for "2010-", to see what you get in return, php.net/manual/en/function.strrpos.php
I've found it. Although the string did not show any html when doing strpos I found it still contained tags. I have removed them with strip tags function. Baffling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.