0

So I'm trying to make a breadcrumb script in php and I'm getting kinda strange errors.

Here's my script:

function bread_crumb(){

…some code before...

foreach ($words as $key => $value) {
    if ($key < count($words) - 1) {
        print '<a href ="';
        print_link($words,$key);
        print '">'.$value.'</a> / ';
    }
}

Here's my print_link() script:

function print_link($w,$max){
$_string = "";
for ($i=0; $i < $max; $i++) { 
    if ($i != $max-1) {
        $_string += "/".$w[$i];
    } else {
        $_string += "/".$w[$i]."/";
    }

    print $_string;
}

return $_string;

}

It somehow works, but not in a good way. My results are fine between the tags but in the section I get kinda interesting results.

for example this link http://example.com/products/category/
get's translated like this:

<a href ="">Www</a> / <a href ="0">Mondano</a> / <a href ="00">Termékek</a> / <a href ="000">Kategóriák</a> / 

I'm really clueles how does a link become "0". Any ideas ?

Narc0t1CYM
  • 499
  • 6
  • 25

2 Answers2

2

PHP 101: + is mathematical addition.

    $_string += "/".$w[$i];
             ^----

you're doing

$_string = $_string + '/foo';

which ends up basically being

$_string = 0;

Try

    $_string .= "/".$w[$i];
             ^----

instead.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

Why do you use += in your print_link function ? If it's a string use .= instead of +=

Abdelilah Aassou
  • 148
  • 3
  • 15