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.
Related
I want to extract variable lengths of information from a jpeg-file using PHP, but it is not exif-data.
If I open the jpeg with a simple text editor, I can see that the wanted informations are at the end of the file and seperated by \00.
Like this:
\00DATA\00DATA00DATA\00DATA\000\00DATA
Now if I use PHP's file_get_contents() to load the file into a string, the dividers \00 are gone and other symbols show up.
Like so:
ÿëžDATADATADATADATADATA ÿÙ
Could somebody please eplain:
Why do the \00 dividers vanish?
How to get the informations using PHP?
EDIT
The question is solved, but for those seeking a smarter solution, here is the file I try to obtain the DATA parts from: https://www.dropbox.com/s/5cwnlh2kadvi6f7/test-img.jpg?dl=0 (yes I know its corrupted)
Use instead $data = exif_read_data("PATH/some.jpg") it will give you all headers data about image, you can check its manual here - http://php.net/manual/en/function.exif-read-data.php
I came up with a solution on my own. May not be pretty, but works for me.
Using urlencode(file_get_contents()) I was able to retrieve the \00 parts as %00.
So now it reads like this:
%00DATA%00DATA%00DATA%00DATA%000%00DATA
I can split the string at the %00 parts.
I am going to accept this answer, once SO lets me do so and nobody comes up with a better solution.
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?
I have a php string
echo $this->contact->email_to
This outputs the following HTML
me#mymail.com
I want it to output the following HTML
I have been playing around with preg_replace but getting nowhere. I have got as far as the following code but it doesn't work at all.
echo preg_replace(array('/([\w-?&;#~=\.\/]+\#(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i'), array('$1', ''), $this->contact->email_to);
I am no PHP expert so I understand there might be easier ways of doing this but I am having difficulty figuring it out.
This is probably not the best way of doing this, but using preg_replace with HTML tags, and especially emails is always a pain in the butt. Let me know if this works for you:
echo preg_replace("/\>(.*)\#(.*)\</i", "><", $this->contact->email_to);
I am developing a Facebook App in which I get some text from the Database and Display it on the Page.
The Problem is that I want to insert a line Break in the variable e-g
If I copy a Text from database and store it in a Variable..
Let say
$text="I love to walk";
I want to insert a line break after "to" how can i do that?
I had tried to store the text like this in html
"I love to <html> <br> </html> but that didn't worked..
Just suppose this is the Text ..may be next time the text is entirely Differnet having no "to" word.
Depends on if you want to create new line in code output, or in HTML
$nl = "\r\n";
$nl_html = "<br />";
That exmple you provided modify like this:
$lyrics = "I love to <br> but that didn't worked.."
To automatically add line break after some text, use preg_replace
$lyrics = preg_replace('/to /',"to<br />",$lyrics);
see http://php.net/manual/en/function.preg-replace.php
$new_str = str_replace('to', 'to <br />', $str, 1);
If you want to output the text in a html page, you need to make it
$text="I love to <br /> walk";
If you want to output it to a file you need to make it
$text="I love to\r\nwalk";
or
$text="I love to\rwalk"; depending on the OS on which you will be reading the file
Hi I was having issues with this just as you do earlier today (I am new to PHP).
The way I fixed this was as follows:
$format_text = nl2br($formatthis);
You would then refer to $format_text.
What it does is it keeps the line breaks.
However I am not quite sure what you mean with your OP, after re-reading it. I went by the topic and I answered it as best I could.
If you are having trouble let's say echoing html code then most definitely you are having trouble with escaping characters.
For instance:
echo "a href="something" /a this won't work.
echo "a href=\"something\" /a this will work, notice the .
you have two options either use preg_replace or use a variable to save the value
please see php documentation for further info
I want to create a PHP script that grabs the content of a website. So let's say it grabs all the source code for that website and I say which lines of code I need.
Is there a function in PHP that allows you too do this or is it impossible?
Disclaimer: I'm not going to use this for any illegal purposes at all and not asking you too write any code, just tell me if its possible and if you can how I'd go about doing it. Also I'm just asking in general, not for any specific reason. Thanks! :)
file('http://the.url.com') returns an array of lines from a url.
so for the 24th line do this:
$lines = file('http://www.whatever.com');
echo $lines[23];
This sounds like a horrible idea, but here we go:
Use file_get_contents() to get the file. You cannot get the source if the web server first processes it, so you may need to use an extension like .txt. Unless you password protect the file, obviously anybody can get it.
Use explode() with the \n delimiter to split the source code into lines.
Use array_slice() to get the lines you need.
eval() the code.
Note: if you just want the HTML output, then ignore the bit about the source in step 1 and obviously you can skip the whole eval() thing.