pretty new to Mysql, HTML and PHP and I can't seem to find much information on this trouble i'm having.
I Am making my own rough project manager type thing and I have a form that lets me change the contents of each individual change log, the problem I have however is that when I load the data in to the text area it start with a big indentation at the start, like 3-4 tabs inwards. I would attach an image but I need at least 10 rep to do that.
Basically, it feels like the data in the database has tabs or something at the start of it, but when I go to look in PHPmyadmin at the field, it just looks like it should do, not tabbed at all.
I've tried using strip_tags() but I think it only works on visible tags.
Does any1 know how to get rid of this or what is causing the problem?
I'll be following this question closely to see if anybody can provide an answer because I'm stumped.
Thanks,
Try to echo your php code with no blanks :
Possible tabs, bad example :
<textarea>
<?php echo $tabContent; ?>
</textarea>
Avoiding tabs :
<textarea><?php echo $tabContent; ?></textarea>
You can also try to trim your php content like that :
<textarea><?php echo trim($tabContent); ?></textarea>
Try doing var_dump and look how long your queried string is.
If it is as long as in your database you problem is within the textarea.
Is there any css you use with textarea?
Related
Thanks so much to everyone who commented and answered this, The problem was missing a double quote from a div higher up on the page! Embarrassing, but again thanks for your efforts! for the record, my problem was that higher up on the page, there was a div like this: directly before I inserted my dynamic div.
I have a pretty simple problem, but I haven't been able to dig up any info on why it's happening.
basically I'm using php to echo quite a bit of html, about 6 divs. one div in particular always displays wrong when viewed on the browser. I'm using notepad++ encoding UTF-8 without BOM. here is an example:
in my index.php, I write:
<? echo '<div class="DivButton">Logout</div>'; ?>
all I see is the text 'Logout' without CSS. when I view the code in a browser it looks like this:
<div class=" divbutton">Logout</div>
Another clue is that often there are 1 or 2 lines before the class, for example in the browser:
<div style="background:#000; left:0px;">Welcome to your website</div><div style="
divbutton">Logout</div>
and ideas are greatly appreciated
As mentioned above, there is no way from the code provided that whitespace can be generated unless you put it there without intention, HTML ignores white spaces anyway so there shouldn't really be such an issue. The case on the code you provided and the output do not match either? Are these actual snippets or just from what you have wrote here.
<div class="divbutton"><? echo 'Logout'; ?></div>
Try less echo, keep it simple so you can see that you are just echoing the 'Logout', I assume you will want this to be dynamic Login / Logout depending on whether there is a session.
I'm quite new here. I'm trying to make a blog/journal site that allows users to post their own journal. I'm still quite reluctant on making it because I am really afraid of malicious code injections.
So here's a sample code:
<?php
$test = "<b>blah</b>"; //User input from SQL
echo "$test";
?>
What will come out is just the word "blah" in bold right? What I was trying to achieve was to echo "<b>blah</b>" instead. I don't want people to put some PHP codes that can actually mess up my whole web page. Please keep in mind that the variable $test is actually a MYSQL query, so that variable will be needed as an example. I know you can do echo '$test'; but it just comes out as "$test" instead. I feel like pulling my hair out I can't figure it out yet.
The second solution I know of is the htmlspecialchars(); function, but I want the strings to display as what I typed, not the converted ones...
Is there any way I can do that?
I think the OP wants the HTML itself to be output to the page, and not have the tags stripped. To achieve this, you can run the string first through htmlentities()
$test = '<b>blah</b>';
echo htmlentities($test);
This will output:
<b>blah</b>
Which will render in the page as
<b>blah</b>
Echo don't execute PHP code from string. This is impossible and this is not security hole in your code.
You can use a template engine like Twig for exemple.
If htmlspecialchars(); is not the one you are looking for, try the header() option.
header('Content-type: text/plain');
When you are gonna give <b>Hi</b> to a browser, it will be displayed in Bold and not the text be returned. But you can try this way, outputting it inside a <textarea></textarea>.
Or the other way is to use htmlentities():
<?php
$test = "<b>blah</b>"; //User input from SQL
echo htmlentities("$test");
?>
I want to display html code just like what your see here.
<textarea><script id="ff">gdgdgs</script></textarea>
and have it displayed without altering the page. and have it nicely within a box like this.
How is this achieved?
I think the best way is to actually have a look and see how Stackoverflow does it! :)
If you right click on your code box in Chrome and select inspect element, it'll show you the markup for that box. It's so useful to be able to do this, obviously not to rip people off, but learn how other people put websites together, and how they achieve cool effects like code boxes! :)
Interestingly enough though, if you simply right click on the page and go to view source, you'll see something slightly different:
<pre><code><textarea><script id="ff">gdgdgs</script></textarea>
</code></pre>
So we can see here that this is what the mark-up for that box looks like before the page has loaded and any JavaScript is run. When the page starts to load on the client side, some JavaScript will be run which takes the above mark-up and tranforms it to look like the mark up you see when you right click on the code box and inspect it in chrome. Doing this gives you a real-time view of the HTML on the page:
<pre class="lang-php prettyprint">
<code>
<span class="tag"><textarea><script</span>
<span class="pln"></span>
<span class="atn">id</span>
<span class="pun">=</span>
<span class="atv">"ff"</span>
<span class="tag">></span>
<span class="pln">gdgdgs</span>
<span class="tag"></script></textarea></span>
<span class="pln"><br></span>
</code>
</pre>
So if you have a look, you can see the transformed code uses a pre tag. This basically says, anything between here you can treat as a literal or in otherwords, keep line breaks and spaces where I left them!
As well as using the pre tag to wrap the code, you can also see that they use different CSS classes. This is to achieve the color coding you can see.
They also use a code tag which as far as I can see, is very similar to pre, only it makes your markup a bit clearer by saying, within this tag, you should expect to see code. It's probably more semantic more than anything, like the HTML tag artical. In most browsers, it'll also change the font for text inside the code tag to mono-space, which is a bit more code like! :)
You can go furhter into this and see exactly what their CSS classes look like, from this you can start to build a mental picture to see how their mark-up and CSS works together to product their nice code boxes.
Of course, if you don't want to roll this functionality yourself, you can use someone elses framework to achive this. SyntaxHighlighter for example if widely used and recommended.
With Syntax Highlighter, you simply reference the Syntax Highlighter CSS and javascript, and then only need to wrap your code in one pre tag to get it working, something like below:
<pre class="brush: xml">
<textarea><script id="ff">gdgdgs</script></textarea>
</pre>
It might be worth a look!
Hope this helps! :)
you could use
>
>
and
<
<
This website here can help you with your particular problem. It converts your tags/html/javascript to ASCII. If you need a function, here it is. It converts the passed tags/html/javascript to ASCII. The ASCII code is escaped and treated as text by the browser. You can latter use the generated ASCII and add it to the box.
function stringToAscii(s)
{
var ascii="";
if(s.length>0)
for(i=0; i<s.length; i++)
{
var c = ""+s.charCodeAt(i);
while(c.length < 3)
c = "0"+c;
ascii += c;
}
return(ascii);
}
Use the Encoded Version like this:
<textarea>
<script id="ff">
gdgdgs
</script>
</textarea>
Is this what you mean?
<textarea><script id="ff">gdgdgs</script></textarea>
Look up HTML entities.
Yeah, just include it like:
$(document).ready(function(){
var a = '<textarea><script id="ff">gdgdgs</scrip'+'t></textarea>';
$("div").css('background','red').text(a);
});
I use the <xmp> element.
I've got a php file that takes an xml file (generated by an outside source) and reformats it with CSS & HTML. A number of the XML tags are things I don't want to see in the final version, so I have them hidden. The end result is something like this:
<html>
<div style="display: none">
content i don't want to see
</div>
content I do want to see.
</html>
Is there a way I can take the resulting html file as it's displayed in the browser window,
content I do want to see.
…and save that as a text file? I want it to ignore all the hidden <div> tags and only save what can otherwise be selected and copied by the user.
I've looked around for an answer to this but I'm not even really sure what I'm looking for or how to search it.
I've also tried this:
ob_start();
file_put_contents('filename.htm', ob_get_contents());
ob_end_flush();
… but that's doesn't solve it. I have a number of tags in the outputted test (> etc) that need to be saves as they are displayed, and ob_get_contents() takes the page's source code, not the displayed version.
This matters because the outputted page is also PHP that has been generated based on other factors, so I need to use html unicode values to keep the $ signs and quotes from messing up the source PHP.
I hope that was clear. Thanks in advance for any help or suggestions.
I think you have to strip out the unneeded part manually, using a RegEx something, which maybe like:
$content_raw = ob_get_contents();
$content_stripped = preg_replace($content_raw, '<div style="display: none">[^<>]*</div>', '');
file_put_contents('filename.htm', $content_stripped);
I'm trying to experiment with taking text from a textarea in a flex project and open it up in a php page. But the php isn't line breaking where it should be...
an Example of the text i'd like to bring over to php would be:
You: Hi there
Them: Hello
You: This is a great example
Them: I know right?
Here's my php:
<?php
$text= $_GET['text'];
echo $text;
?>
Right now I came up with something like this in the actionscript...
var chatBox:String=chat_box.text;
navigateToURL(new URLRequest("savelog.php?text="+chatBox), '_blank');
I also tried something like:
var chatBox:String=chat_box.text.valueOf().replace("\n","<br/>");
and
var chatBox:String=chat_box.text.toString().valueOf().replace("\n","<br/>");
But apparently the \n isn't translating over no matter how I get the chatBox var so its not even making a <br/>
But, even if i did get that to work it wouldnt be ideal. Because eventually in the end I want to be able to just incorporate the pastebin API to paste this GET data and post it on there. And I don't think it would look too pretty with having <br/> after every line...
So my questions is, is it possible to bring this text over to php and recognize the line breaks in a way that would work well with what im eventually trying to accomplish?
edit:
I'm a little confused because var chatBox:String=chat_box.text.toString() actually returns the text with \n at every line break and i can see the \n on a trace statement...but when im looking in the URL text there is no \n anywhere...any ideas? because if the \n would appear the ln2br() solution might work
Take a look at ln2br() its a built in function in PHP. It also handle more than jsut the \n might be usefull in your case and i dont see that your using it yet! Try it out and let me know! You also might want to check out any encoding issues.