mailto php removing new line characters - php

I'm using a mailto link to send e-mail with a php string variable inside it as follows:
'Would you like to E-mail stakeholders? <a class="emailLink" href="mailto:stakeholders?subject=Alert '.$ticket.'&body=Experience: %0D%0A'.$exp.'">Review and Send!</a><br><br>';
I discovered that in the e-mail client it prints it out like:
Experience:
Th Experience should contain:\r\n\r\nImpact\r\nHow to replicate\r\nComprehensive notes
So I tried:
$charactersToRemove = array("\r\n","\n","\r");
$replaceWith = "%0D%0A";
$exp = str_replace($charactersToRemove,$replaceWith,$exp);
Which doesn't seem to make a difference...Can someone tell me why? Thanks.

Can you post more of your code to show how $exp was assigned it's value?
I've edited out my answer until I can provide better help.
EDIT: Can you seriously try using "\r\n" with \" to escape "'s instead, just in case PHP is somehow localizing %0D$0A in your HTML output? What does the source of your page look like?

Related

Parsing spaces into html header

I am trying to google a solution for parsing a PHP variable "Joe Soap"
into a html header
I am expecting:
http://myurl.com&name=joe soap
but I am getting
http://myurl.com&name=joe
I know I can not have spaces in my http header but I can't find out how to parse my variable.
I just need a hint so that I can google it.
Regards
Without some code it's guessing work.
I think you need PHP urlencode
$test = 'Joe Soap';
echo 'http://example.com/?name=' . urlencode ( $test );
Which results in: http://example.com/?name=Joe+Soap
2 minutes after I ask the question, I find the answer.
use the urlencode function in php
regards

Convert Plain Text Address to clickable link to google maps via PHP

Pulling in data from a Filemaker Pro database field and trying to convert the plain text data from the field into a clickable link to google maps via PHP.
My first attempt doesnt display anything when called:
$Venue = '';
$Venue is then echoed into a UL via
<?php echo $Venue; ?>
I'm relatively new to PHP so I'm sure there is a much more semantic way of marking this up? Possibly a regex and replace, returning a preg_replace? Which is what I've been using for plain text URLs and email addresses.
Anything helps, thanks so much.
Casey - not sure there's enough context here to help you? For instance, forget the link wrapping, does
<?php echo $record->getField( 'Auctions::AIS_Venue'); ?>
actually echo the field contents to a page?
Also, not sure you really want to use nl2br anyway, as you probably don't want a break in your url ;-)
OK, in which case there are a couple of things to try. First - can you get it to run in a webviewer inside FileMaker? I suspect not, and it may be down to an encoding/filtering issue.
There are two approaches you could use.
Create a new calc field in FileMaker that filters out punctuation and converts spaces to '+'s, something like:
Filter( Substitute( Lower( Auctions::AIS_Venue ) ; [ ¶ ; "+"] ; [" " ; "+"]; ["++" ; "+"] ); "abcdefghijklmnopqrstuvwxyz1234567890+" )
and then use that field as in your PHP code, or;
Do the same calculation on the fly in PHP, something like:
$Venue = '';
That should do the trick ? ;-)

How to prevent GMail from converting text to URL?

I have a small issue with GMail. My company has a ".fr" part in its name, and when we send newletters, GMail shows it as an internet adress and autmatically adds a link to it.
That's not what I want.
I found a very good solution here, and it works like a charm when I manually edit the HTML file. The magic is to add a character GMail does not know, like ­, so that is does not transform the text into a link.
The problem is when I try to automate this replacement :
$body = str_replace('my company.fr', "my company­.fr", $body);
PHP does not seem to see this ­ character, and for the little story, neither does Google...
Do you know of a way to achieve my goal, that is not having a link on my company name ?
I could do the second option in the above mentioned article, but that, to my opinion, would be my last option.
Thanks for your replies !
You can need ' not " for this special char
$body = "my company.fr"
$body = str_replace('my company.fr', 'my company­.fr', $body);
//result is my company­.fr
And using html_entity_decode for back
$st = "my company­.fr"
$st = html_entity_decode($st);
//result is my company.fr
Hope this help!

Passing HTML entities through URL

I am trying to pass the Euro symbol i.e "€" and the "#" symbol, but they are not working, the euro symbol is looking like "€" and the "#" symbol is looking like "%40", I am using "urlencode()" function in PHP, but it doesn't seem to work, please let me know what could be wrong.
P.S I am transferring data from GET to another page then sending it in email, in email it is looking like the above.
EDIT: This is page 1:
$temps=urlencode($temps);
header('Location:http://someurl.com/mailx.php?data='.$temps);
This is page 2: Here I am emailing the data.
$mailmsg = $_GET['data'];
Output seen in my email inbox:
Email: name%40gmail.com
Notice that %40 instead of "#"?
You need urldecode(), read more here.
$var = "name%40gmail.com";
echo urldecode($var);
//output name#gmail.com

Storing line break in a php Variable

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

Categories