简体   繁体   English

将HTML文本转换为输入字段

[英]Transform HTML text into input field

Consider a standard web page created with PHP passing some text variables, taken from a database, to an HTML file. 考虑用PHP创建的标准网页,该网页将从数据库中获取的一些文本变量传递到HTML文件。

I would like to be able to modify the value of the variables using as an interface the real HTML file (so one can actually see where the variables are in the page). 我希望能够使用真正的HTML文件作为接口来修改变量的值(这样一来,人们就可以实际看到变量在页面中的位置)。

I tried simply using a substitution like " $variable --> < input value="'.$variable.'"/> ". 我尝试简单地使用诸如“ $variable --> < input value="'.$variable.'"/> ”之类的替代$variable --> < input value="'.$variable.'"/> This works only in some cases. 这仅在某些情况下有效。 For example it doesn't work if the variable is the content on an <a> tag or if the variable contains some HTML. 例如,如果变量是<a>标记上的内容或变量包含一些HTML,则它不起作用。

Do you have any suggestion on how I could accomplish this? 您对我如何完成此工作有任何建议吗? Is there a way to force <input> tags anywhere in my HTML file, so that they can be seen from the end user? 有没有一种方法可以在我的HTML文件中的任何地方强制<input>标记,以便最终用户可以看到它们?

This is the default and the easiest way to edit your variables (content of your site) 这是默认的和最简单的方式来编辑变量(网站内容)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Edit</title>
</head>
<body>

<?php
    $title = "Lorem Ipsum";
    $content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry <strong>Lorem Ipsum</strong> has been the industry's <a href=\"http://justin-bieber.com\">standard dummy</a> text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
<pre>function toggle(o) {
    var e = document.getElementById(o);
    e.style.display = (e.style.display != 'none' ? 'none' : '' );
}</pre>";
    $author = "Anonymous";
?>

    <form enctype="multipart/form-data" method="post" action="_URL_">
        <label>Tilte</label><br /><input type="text" name="title" value="<?php echo  stripslashes($title) ?>" /><br />
        <label>Content</label><br /><textarea name="content"><?php echo stripslashes($content) ?></textarea><br />
        <label>Author</label><br /><input type="text" name="author" value="<?php echo  stripslashes($author) ?>" /><br />
        <input type="submit" name="submit" value="submit" />
    </form>

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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