Help basename + url [PHP] [closed]

0

I have this code:

if(count($vid_files)>0){
    $videoNames = array_keys($vid_files);
    $videoName = basename($videoNames[0]);
    $this->videourl = $videoName;

I would like to add a url at the beginning after the result of basename , resulting from it is 100392video.mp4 I wanted the url to stay ahead, / p>

$this->videourl = "url" + $videoName;

But when I do this, it comes out just the numbers.

100392

And there is no url or the ending that is .mp4 .

In response to Isac;

    public function add($f3, $id, $name, $userid, $category, $vid_files){
        //add or edit to db
    if($id>=0){
        $this->load(array('id = ?',$id));
    }
    $this->userid = $userid;
    $this->name = $name;
    $this->category = $category;

    if(count($vid_files)>0){
        $videoNames = array_keys($vid_files);
        $videoName = basename($videoNames[0]);
        $this->videourl = $videoName;
    }

    $this->save();
}
    
asked by anonymous 04.02.2018 / 22:30

1 answer

1

The problem occurs because you are "adding" and not "concatenating."

Change this:

$this->videourl = "url" + $videoName;

so:

$this->videourl = "url" . $videoName;

The old code adds numbers, in the case url is the 0 and video name 100392 , so the result.

As stated in the PHP documentation

String Operators

There are two string operators. The first is the concatenation operator ('.') , which returns the concatenation of its right and left arguments. The second is the concatenation operator ('.=') , which adds the argument on the right side in the argument on the left side. See Assignment Operators for more information.

<?php
$a = "Olá ";
$b = $a . "mundo!"; // agora $b contém "Olá mundo!"

$a = "Olá ";
$a .= "mundo!"; // agora $a contém "Olá mundo!"
?>

For numbers, yes, we use +

echo 1+2; //mostra o numero 3

But calm

It is normal for these errors to occur, especially for those who develop in languages such as java that string concatenation is done with + as well.

    
05.02.2018 / 21:09