Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrapping of auto-generated URLs

Status
Not open for further replies.

alinna

Technical User
May 10, 2004
2
0
0
GB
Hi

I have developed a website which involves people posting through an admin section to the website. They can copy and paste text, including URLs which need to start with "
To convert URLs I use the following piece of code:

Code:
<cfset str = "#ReReplaceNoCase(str,"([URL unfurl="true"]http://+[/URL][a-zA-Z0-9\.-]+[a-zA-Z{2,3}[a-zA-Z0-9&/\.\%?=_-]\.[a-zA-Z0-9\.-]+[a-zA-Z{2,3}[a-zA-Z0-9&/\.\%##''|+_?=~)(_-]*)","<a href=""\1"" target=""_blank"">\1</a>","ALL")#">

This works very well.

The problem I now have is that long URLs do not wrap. And this stretches the page to as long as the URL is. I have not found a solution to this.

Can you help?

With many thanks
Alinna
 
If you ever find the solution to this, let me know. I've searched on and off for a few years on this exact problem.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I am in the same boat and have never found a solution.

The only thing that works for me is to add spaces after the slashes in the URL to break it up. So Alinna, you would build two strings, one for the href and one to display...
 
I think I've found the solution - and it's incredibly simple, and only available for CF MX 6.1:

The use of wrap() - so in this case, just before displaying #str# I've written: <cfset str = "#wrap(str,68)#">

However, I came across loads of problems doing this, as the wrapping would interfere with the HTML. The solution (after much mucking about), was to leave a space between each HTML code - as wrap() wraps either at a space of the "limit". More about wrap here:
So the answer has turned out to be:

<!--- note the spaces around the HTML --->
<cfset str = "#ReReplaceNoCase(str,"([a-zA-Z0-9\.-]+[a-zA-Z{2,3}[a-zA-Z0-9&/\.\%?=_-]\.[a-zA-Z0-9\.-]+[a-zA-Z{2,3}[a-zA-Z0-9&/\.\%##''|+_?=~)(_-]*)"," <a href=""\1"" target=""_blank""> \1 </a> ","ALL")#">
<!--- now to wrap up everything - I've chosen a limit of 68, but any number works --->
<cfset str = "#wrap(str,68)#">
#str#


Using this, now enables users to enter text into a textarea and for this text to be displayed correctly - no fiddling around with URL field boxes etc...

Thanks again for all your help, and I hope you find this useful!
Alinna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top