Link to home
Create AccountLog in
Web Languages and Standards

Web Languages and Standards

--

Questions

--

Followers

Top Experts

Avatar of lutt
lutt

How to force hyperlink to wrap?
I have this web application, which pulls data from database into <td> field. The <td> field has a fixed width. The data constains a samll paragraph. But if the data contains very long urls, then <td> field will strech as long as the url and overide <td> field width. Is there a way I can force the url to wrap as regular texts?

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of pinaldavepinaldave🇮🇳

Hi,
I do not think that it can be done.
Just curious why do not you do this
<a href = "very very long url">Short name</a>
If url is very long no body will write it down but will copy it which can be still done using write click or when they click and this page is open.
Regards,
---Pinal

Avatar of luttlutt

ASKER

The data  I am pulling from DB is just texts, which sometime contain words like: http://www.******************************. These words just don't wrap like the regular words.

Avatar of StormyWatersStormyWaters🇺🇸

<a href = "<?php echo YOUR DATABASE STUFF ?>"> Clicky here! </a>

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of luttlutt

ASKER

StormyWaters,

The data is not only urls, also contains other words. Urls are not always part of the data.

Make the Table TD widths in Relative percentages. Try  Using a <br> tag after so many characters. Mine wraps u might take alook at som of the source, as far as the url goes u cant stop anyone from makeing copys without using a complex javascript to generate it off an array of chars(being the url) or something. Try converting  the data into post format if u can. you can do this in php using the $_Server variable. i sugeest doing this:
<?php

any other data actions
$ShortName=SHortNAmeHere
$URL=Url-Goes-here
echo "<a href=".$URL.">".$ShortName."</a>";
?>

I assume you are probably using SQL querys and retreving all the data try:
Assuming result is the result of the query

<?php
#All the databse crap


while($line=mysql_fetch_row($result))
{
#Data Functions
#this assumes column 1 is the URL and column 2 is the short name u want for it.
$ShortName=$line[1];
$URL=$line[0];

echo "<a href=".$URL.">".$ShortName."</a>";
}
?>

Guys, I think what he's saying is he'll pull something like this from his db:

"Howdy People!  My website is http://www.mytestsite.com"

But it won't wrap when it comes to the url.  And, to finish up my comment, here's what you need to use:

$message_wrapped = wordwrap($message, 30, "\n", 1);

See http://us2.php.net/wordwrap


CoolATIGuy

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of COBOLdinosaurCOBOLdinosaur🇨🇦

Add this to the table tag: style="table-layout:fixed"

apply this style to the td taqs:

<td style="width:100px;overflow:hidden;clip:auto">

It still won't break the line to wrap it, but it will truncate the data instead of pushing out the cell width.  Set the with to whatever you need in pixels.

Cd&

I suppose inserting <wbr> tags after slashes in the link text (but not within anchor tags) would be quite a hassle. I don't even know if <wbr> is recognized any more let alone "anybrowser compliant".

Avatar of COBOLdinosaurCOBOLdinosaur🇨🇦

wbr is non-standard.  It has never been included in any HTML specification.  Its support is limited to IE and early versions of Netscrap (4 and prior).  It is completely unrelaibe except within a nobr tagged element which is also non-standard.  

So the net effect is you put the content in a nobr tag to tell it to never insert a line break, and then insert  a wbr tag to tell it you changed your mind and you want it to break, and it is ignored by standards compliant browsers; with no guarantee it will contiue to have support in future releases of IE which is the only browser still supporting it.  

Probably not a good idea.

Cd&

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of luttlutt

ASKER

The url and other texts are mixed together. Anyother solution except truncating the url?

ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaurCOBOLdinosaur🇨🇦

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of COBOLdinosaurCOBOLdinosaur🇨🇦

Sorry we did not have a more ideal solution.  Thanks for the A. :^)

Cd&
Web Languages and Standards

Web Languages and Standards

--

Questions

--

Followers

Top Experts

Web development can range from developing the simplest static single page of plain text to the most complex web-based internet applications, electronic businesses, and social network services using a wide variety of languages and standards, including the familiar HTML, JavaScript and jQuery, ASP and ASP.NET, PHP, ColdFusion, CSS, PHP, Flex and Flash, but also the implementation of a broad list of standards including XML, WSDL, SSDL, VoiceXML and many more.