Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with hyperlink formating

Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#1: Jul 9 '09
Hi,

I have a database record which contains the contents of an email
and in the email there should be a clickable link.

For some reason the link is not formatting correctly.

Maybe it is something to do with br's and nl's ?

This is what I input in the database record:

Expand|Select|Wrap|Line Numbers
  1. Then click here to grab a copy of the definitive guide to CPA Marketing!
  2. url=http://www.example.net/sp/cpa-cash/]CPA-Cash Profits[/url]
  3.  
  4. See you again in part 4.
( I took out the leading [ )

This is what I have in the email:

Quote:
Then click here to grab a copy of the definitive guide to CPA
Marketing! target="_blank">CPA-Cash Profits

See you again in part 4.
My code now looks like this:

Expand|Select|Wrap|Line Numbers
  1. $to = $cl_email; 
  2. $contact = $cl_name;
  3. $subject = $camp_row['title'];
  4. $cur_mess = $cp_mes;
  5. $message_html = eml_bbcode($cur_mess,$contact);
  6. $message_html = wordwrap($message_html, 70, "\n");
  7. $message_html = nl2br($message_html);
  8. $message_html = str_replace("<br />", "<br>", $message_html);
  9. $message_html = $message_html."<br><br> 
  10. and my eml_bbcode() function is:
  11.  
The eml_bbcode() function in there is used to
format the text with html.

Expand|Select|Wrap|Line Numbers
  1. function eml_bbcode($Text,$client) {
  2.  
  3. // Replace any html brackets with HTML Entities to prevent executing HTML or script
  4. /
  5. // Don't use strip_tags here because it breaks [url] search by replacing & with amp
  6. $Text = str_replace("<", "&lt;", $Text);
  7. $Text = str_replace(">", "&gt;", $Text);
  8.  
  9. // Set up the parameters for a URL search string
  10. $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
  11.  
  12. // Perform URL Search
  13. $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
  14.  
  15. // Check for client flag
  16. $Text = preg_replace("(\[client\])is","$client",$Text);
  17.  
  18. // Check for bold text
  19. $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<b>$1</b>',$Text); 

The problem is that the target="_blank"> is not getting
identified as part of the hyperlink, even though is looks like a valid format ( to me ).

Can anyone spot where I have gone wrong ?

Thanks

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#2: Jul 10 '09

re: Problem with hyperlink formating


Hi.

Can you show us the exact HTML that your code is generating?

P.S.
You can pass FALSE as the second parameter into the nl2br function to make it generate HTML breaks (<br>) rather than XHTML breaks (<br />).
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,655
#3: Jul 10 '09

re: Problem with hyperlink formating


Quote:

Originally Posted by jeddiki View Post

( I took out the leading [ )

you can use &#91;. this will print as [ but won't act as bbcode.
Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#4: Jul 10 '09

re: Problem with hyperlink formating


Hi,

I dont out put the result as HTML page, I just send
it as an email.

I tried looking at the source code for the mail in the gmail page but I could not find the email content - even a search in the source can out negative - don't know how they hide it - maybe its all encoded ?
Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#5: Jul 10 '09

re: Problem with hyperlink formating


OK - I see my problem now.

It is the wordwrap function that is breaking the line up.


Expand|Select|Wrap|Line Numbers
  1. $message_html = wordwrap($message_html, 70, "\n"); 

Because of the space before the target word, the line gets broken at that point.

I took out that space but now the link doesn't work because of the sapace between the <a and the href .

I think that problem is because this part:

Quote:
href="http://www.example.net/sp/cpa-cash/index.php"target="_blank">
is over 70 characters long.
I am not sure what to do about this
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#6: Jul 10 '09

re: Problem with hyperlink formating


Is there any specific reason why you are using the wordwrap function?
I know it was common to break up messages in the old days but no decent email client today should mind, and certainly not if you are sending HTML mails.

If you insist on breaking it up, try doing it before you convert the BBCode into HTML. You might have to adjust your regexp to cover multiple lines, tho, in case the [url]...[/url] line gets broken.
Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#7: Jul 11 '09

re: Problem with hyperlink formating


Having the wordwrap makes it much quicker to format
my emailsl so they are "easier on the eye".

Do you mean like this: ?

Expand|Select|Wrap|Line Numbers
  1. $message_html = wordwrap($message_html, 70, "\n");  
  2. $message_html = eml_bbcode($cur_mess,$contact);
  3. $message_html = nl2br($message_html);
  4. $message_html = str_replace("<br />", "<br>", $message_html);
  5.  
I am not sure what I would nned to do to make sure that this code of my bbcode will still work:

Expand|Select|Wrap|Line Numbers
  1. // Set up the parameters for a URL search string
  2. $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
  3.  
  4. // Perform URL Search
  5. $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", "<a href=\"$1\"target=\"_blank\"> $2</a>", $Text);
  6.  
The only place it can get broken now is at the space just
before the href label.

Any ideas on this ?
Reply