简体   繁体   中英

PHP Run Function and echo Result

I need to check a name (from $_GET) several times against a current passed name. The function called is checkName and the $_GET is $CurrentName, the passed name to check if equal is $ActiveName. I need to echo the result for font color and passed name. See code below.

Error I get: Fatal error : Uncaught Error: Function name must be a string in Filename.php:33 Stack trace: #0 {main} thrown in Filename.php on line 33

<!DOCTYPE html>
<head>
<title>JW.APK</title>
<style>
@font-face {font-family: 'SourceSansProRegular'; src: url('font/SourceSansPro-Regular.ttf') format('truetype'); font-weight: normal; font-style: normal; }
@font-face {font-family: 'SourceSansProBlack'; src: url('font/SourceSansPro-Black.ttf') format('truetype'); font-weight: normal; font-style: normal; }
body {color:#151515; font-family: SourceSansProRegular; padding: 5px; }
textarea {width: 100%; }
th {position: fixed; left: 0px; top: 0px; width: 100%; }
td {font-size: 0.75em; }
table {margin-top: 10px; width: 100%; border-collapse: collapse; }
font {font-weight: bold; }
p {font-size: 0.7em; text-align: justify; }
</style>
</head><body>     
<?php
$CurrentName = $_GET["name"];
echo $CurrentName;

function checkName($ActiveName)
{
    if ($CurrentName == $ActiveName)
    {
        echo "<font color='#235689'><b>$ActiveName</b></font>";
    } else {
        echo "<font color='#000000'><b>$ActiveName</b></font>";
    }
}
?>
<table border='0' width='100%'>
 <tr>
  <td width='40%' bgcolor='#AED7FF' height='30' >Name 1</td>
  <td width='60%' bgcolor='#AED7FF' height='30' ><?php $checkName("Robert"); ?></td>
 </tr>
 <tr>
  <td width='40%' bgcolor='#AED7FF' height='30' >Name 2</b></td>
  <td width='60%' bgcolor='#AED7FF' height='30' ><?php $checkName("Jackson"); ?></td>
 </tr>
</table>
</body>
</html>

I need to call the function many times.

You are calling the function in a wrong way in the table. the correct way of calling the function is checkName("Robert") without the $.

If you want to compare that $CurrentName , you can pass that $CurrentName as a argument in checkName function and use it inside the checkName function. Now Call the function without $ eg. checkName($ActiveName, $CurrentName);

$CurrentName = $_GET["name"];

function checkName($ActiveName, $CurrentName) {
    if ($CurrentName == $ActiveName) {
        echo "<font color='#235689'><b>$ActiveName</b></font>";
    } else {
        echo "<font color='#000000'><b>$ActiveName</b></font>";
    } 
 }

$ActiveName = "Monkey D Luffy"
checkName($ActiveName, $CurrentName)

Hope this helpful,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM