Search code examples
mysqlwordpressspecial-characters

echoing out @ symbol when pulling emails from mysql database in WP page


Here is the code I'm using that is pulling all data fields nicely from mysql database. But email addresses are being displayed as user%40domainname.com instead of standard email output of [email protected].

$myData = mysql_query($sql);

echo "<table class='table table-hover table-bordered table-striped'>
          <tr>
              <th>Username</th>
              <th>Email</th>
              <th>Score</th>
          </tr>";

while($record = mysql_fetch_array($myData)) {
    echo "<tr>";
    echo "<td>" . $record['id'] . "</td>";
    echo "<td>" . $record['email'] . "</td>";
    echo "<td>" . $record['score'] . "</td>";
    echo "</tr>";
}

echo "</table>";

Solution

  • You can use urldecode to solve this:

    $email = 'user%40domainname.com';
    echo urldecode($email); //[email protected]
    

    demo: http://ideone.com/hEdpxk

    ... or in your case you can use the following while loop:

    while($record = mysql_fetch_array($myData)) {
        echo "<tr>";
        echo "<td>" . $record['id'] . "</td>";
        echo "<td>" . urldecode($record['email']) . "</td>";
        echo "<td>" . $record['score'] . "</td>";
        echo "</tr>";
    }