Number 1 is concatenated to the end to array element. How to get rid of this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    Number 1 is concatenated to the end to array element. How to get rid of this?

    I am getting strange behavior:

    my url: http://localhost/MVCfirst/public/Contact/email/anoth
    if i use command
    Code:
    var_dump($url);
    i am getting result:
    array(3) { [0]=> string(7) "Contact" [1]=> string(5) "email" [2]=> string(5) "anoth" }
    where
    Code:
    $url=explode('/', filter_var( rtrim($_GET['url'],'/') ), FILTER_SANITIZE_URL);
    If i use commands:
    Code:
    echo '<pre>', print_r($url[0]), '</pre><br>';
    echo '<pre>', print_r($url[1]), '</pre><br>';
    echo '<pre>', print_r($url[2]), '</pre><br>';
    I am getting as a result words:
    Contact1
    email1
    anoth1
    Number 1 is concatenated to the end.

    How to get rid of 1 concatenated to the end? Because i need word Contact to proceed to controller file and its methods.

    Actually i am following online course:
    https://www.udemy.com/learn-php-model-view-controller-pattern-php-mvc/#/lecture/2201044

    And they make a line in .htaccess:
    RewriteRule ^(.+)$ index.php?url=$ 1 [QSA,L]

    Maybe this line is the reason that 1 is concatenated?
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.

    "When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE. "

    so, when you do:
    $b="test"; echo "A",print_r($b) ,"C";

    PHP will first print the A
    than the value of $b
    then the return value of 'print_r($b)'
    then the "C"
    which is: Atest1C

    Comment

    Working...