Code in original form - php

I have HTML code for a table in database. I want to present that code in its original form in a textarea so that I can make changes in it. When I echo it appears in compiled form (table), not in original HTML code. How can I display its original HTML code?
<textarea rows="40" cols="30" name="content" id="content">
<?php echo '<pre>'.$row['content'].'</pre>'; ?>
</textarea>

You can use the <code> tag to achieve this.

Try replacing < by <
<?php echo '<pre>'.str_replace('<', '<',$row['content']).'</pre>'; ?>

Related

How do you style input that PHP posted with a CSS selector?

I want to create a webpage that posts onto itself text inserted into an input field, using CSS to stylize said text once it becomes part of the page. However, I don't know how to refer to it with a CSS selector. I've done what every HTML-newb tries when encountering a problem and wrapped both the form code and PHP statement in classified DIVs, however, the computer visibly doesn't know what I'm trying to address. Likewise, wrapping the PHP statement in paragraph tags doesn't apply to it the stylization said tags are associated with.
For Reference, Form & PHP Code:
<form method = "post">
<textarea name="input"></textarea>
<input type="submit">
</form>
<?php echo $_POST['input'];?>
My apologies if the solution to this is obvious; I can't find information addressing it.
you could inline style it or with a class.
<form method = "post">
<textarea name="input"></textarea>
<input type="submit" name="submit">
</form>
<div class="input-value">
<?php
if(isset($_POST['submit])) {
echo $_POST['input'];
}
?>
</div>
use .input-value class in css
Please try this!
<form method = "post">
<textarea name="input"></textarea>
<input type="submit">
</form>
<?php echo "<div style='color:red;font-family:verdana;font-size:300%'>" .
$_POST['input'] . "</div>" ?>
Are you looking for this? Please let me know! Thanks!

Cant enter PHP value for <textarea>

I have made a page in HTML/PHP and I would like a function to be able to edit some files though the web-page. I have a <textarea> tag to do this.
However, I cannot seem to enter any default value to the <textarea> through PHP variables.
Here is my code
<?php
$text = file_get_contents("file.txt");
?>
<textarea name="input">
<?php echo $text; >?
</textarea>
But the text that appears is "<?php echo $text; ?>"
Please help, I couldn't find help anywhere else.
You misplaced your ending PHP tag (>? should be ?>) when echoing the result into the textarea.
<?php
$text = file_get_contents("file.txt");
?>
<textarea name="input">
<?php echo $text; ?>
</textarea>
You should check your php knowledge:
line 5 should be ?> not >?. Then it will be valid.

Form Hidden Field Prints out Content to Webpage

I have the following form code:
<form action="pdf.php" method="POST" id="pdfform">
<input type="hidden" name="htmlcontent" value="<?php echo $content ?>" >
<li>Download as PDF</li>
</form>
However, what i realise is that the hidden field prints out the content to the HTML page as well, and there are some extra " and > which should not be there.
What i think could be the issue is because the role of the form is to send the html data to a PHP script to convert it to a PDF, the variable $content contains html code, for example: <p>Test 3</p><p><img alt="Cancer" src="http://breakthroughs.cityofhope.org/wp-content/uploads/2013/02/lung-cancer.jpg" style="height:375px; width:500px" /></p>
This could be one of the causes of the issue and the html prints out the extra "> at the end of the value inside the hidden form as well.
Anyone could find out the reason?
Not sure if this is what you want, but have you considered using jquery to set the hidden field? for example (after ensuring you have no single quotes in your $content variable):
<script type='text/javascript'>
$('[name=htmlcontent]').val('<?php echo str_replace("'","`",$content) ?>');
<script>

php how to get the textarea tag from my sql in a textarea in php

I have a code which is all working right but when the code in the database has a it goes wrong
code like this
<tr><td><b>EN Page Content : </b></td><td><textarea name="pageContent" cols="150" rows="100"><?php echo getContentWithIndex("posts",$_GET['pageID'],"content");?></textarea></td></tr>
and content is like this
<textarea placeholder="Message*:" data-constraints='#Required #Length(min=20,max=999999)' name="SenderHRMessage"></textarea>
so it has the end of the </textarea> as an end for the first one and never display any other content in the first textarea.
Change your code to this: (I have reformatted it so that it fits on the SO post)
<tr>
<td><b>EN Page Content : </b></td>
<td>
<textarea name="pageContent" cols="150" rows="100"><?php
echo htmlentities(getContentWithIndex("posts",$_GET['pageID'],"content"));
?></textarea>
</td>
</tr>
The reason is that if you have HTML code that you want to display as HTML code you need to encode it to text.
See: http://php.net/manual/en/function.htmlentities.php

How to send text area content to next page via post method?

I got a textarea that has some html code in it. I want to send the content of this textarea without any change to next page via post method.
<html>
<form id="myform" name="myform" action="./getdata.php" method="post">
<td><textarea rows="7" cols="15" name="outputtext" style="width: 99%;"></textarea></td>
<input type="submit">
</form>
</html>
and my php code :
<?
$file_contents = $_POST['outputtext'];
?>
<textarea rows="30" cols="150"><?PHP print_r($file_contents); ?></textarea>
The problem with my code is that the orginal content of my first textarea gets changed when it sends to next page! For example:
<a href="/season/episodes.php?name=ok&id=1">
becomes:
<a href=\"/season/episodes.php?name=ok&id=1\">
could you guys how i can preserve the original html content without it changes in next page ?(Note all my html content changes in second pages which i dont want to change).My second textarea in second page is for testing purpose and i actually want to parse orginal value of $file_contents but for some reason it changes!
In your second PHP script, simply use strip_slashes to remove the extra slashes in the passed text:
<?
$file_contents = stripslashes($_POST['outputtext']);
?>
<textarea rows="30" cols="150"><?PHP print_r($file_contents); ?></textarea>

Categories