变量值是两个字符串

Somehow a variable that SHOULD contain only one string (not an array or anything) contain an url, managed to contain two different values;

string(8) "value 1 " string(7) "value 2"

i cannot use this variable because echoing it or using it in another function would print

value 1 value2

which is not what i need, i need only value 1 and i cannot use $var[0]

Two things; how can i do something similar (one variable two strings), and how can i manipulate it. EDIT : here is the code

public function get_first_image($post) {
        $image_id=get_post_thumbnail_id($post->id);
        $image_url = wp_get_attachment_image_src($image_id,’large’);
        $image_url=$image_url[0];
        var_dump($image_url);
        return $image_url;
    }

the var_dump() results are as mentioned above

Best Regards

Don't reuse $image_url as a variable, this is most likely causing your problem. You should rename one of your variables:

public function get_first_image($post) {
    $image_id = get_post_thumbnail_id($post->id);

    $image_array = wp_get_attachment_image_src($image_id,’large’);
    $image_url = $image_array[0];

    var_dump($image_url);
    return $image_url;
}

You question doesn't give a great amount of detail. If you need access to part of a string you can use the explode() function. So if the string contained no spaces between the separate values, you could use $newstring = explode(" ",$oldstring); echo $newstring[0]; This would then give you access to the first part of the string.

I'd recommend you look up string concatenation.

If you can give us further details, we may be able to assist you further.