PHP函数返回值为html标记 [英] PHP function return value to html tag
本文介绍了PHP函数返回值为html标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Class.php中,我有一个名为login的函数,用于验证函数的返回值是否为密码正确/不正确
<?php
class Class
{
public function login()
{
if($ _ POST ['password'] == Match){
return'Correct Password!';
} else {
return'密码错误!';
}
}
}
以及我的索引。 PHP我有这个HTML。现在我怎么才能在我的html标签中获得我的登录函数的返回值,其ID为check
<?php
require_once'Class.php';
$ class = new Class();
$ class-> login();
?>
<!DOCTYPE html>
< html>
< head>
< title> SOMETHING< / title>
< / head>
< body>
< form action =method =POST>
< input type =textname =username>
< input type =passwordname =password>
< span id =check>< / span> <! - 我想把返回的值放在这里 - >
< input type =submitvalue =Login>
< / form>
< / body>
< / html>
解决方案
< ?php
require_once'Class.php';
$ class = new Class();
$ returnedValue = $ class-> login();
?>
<!DOCTYPE html>
< html>
< head>
< title> SOMETHING< / title>
< / head>
< body>
< form action =method =POST>
< input type =textname =username>
< input type =passwordname =password>
< span id =check><?= $ returnedValue?>< / span>
< input type =submitvalue =Login>
< / form>
< / body>
< / html>
I want to get return value of a function and display it to a specific id.
In my Class.php I have a function named login that validates if the password is correct/incorrect
<?php
class Class
{
public function login()
{
if($_POST['password'] == Match) {
return 'Correct Password!';
} else {
return 'Incorrect password!';
}
}
}
and in my my index.php I have this html. now how can I get the return value of my login function in my html tag with an ID of check
<?php
require_once 'Class.php';
$class = new Class();
$class->login();
?>
<!DOCTYPE html>
<html>
<head>
<title>SOMETHING</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<span id="check"></span> <!-- I want to put the returned value here -->
<input type="submit" value="Login">
</form>
</body>
</html>
解决方案
<?php
require_once 'Class.php';
$class = new Class();
$returnedValue = $class->login();
?>
<!DOCTYPE html>
<html>
<head>
<title>SOMETHING</title>
</head>
<body>
<form action="" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<span id="check"><?= $returnedValue ?></span>
<input type="submit" value="Login">
</form>
</body>
</html>
这篇关于PHP函数返回值为html标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文