Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP "&curren" string turns into weird symbol

Tags:

string

php

The following PHP code:

<?php
$s = "page.com?a=1&current";
echo $s;

outputs the unexpected:

page.com?a=1¤t

Setting the file encoding to utf-8 didn't work. When I set $s to "page.com?a=1&curre", the output is as expected.

I want to know if this is because in my project I have $url, which needs to be appended with "&currentPage=1".

What is causing this problem?

like image 682
user1712263 Avatar asked Dec 26 '16 20:12

user1712263


1 Answers

That's the entity code for the currency symbol being interpreted. If you're building your GET url, you can solve it in various ways:

  • Use urlencode() on your query values:

    $s = 'page.com?' . urlencode("a=1&currentPage=2");

  • Use the entity for & itself;

    'page.com?a=1&amp;currentPage=2'

  • Or use your variable at the beginning so no & is required:

    'page.com?currentPage=2&a=1'

like image 112
sidyll Avatar answered Sep 21 '22 17:09

sidyll