Hi there,
I have a form, and i want to prevent
words (inserted in a multiline textfield)
to become too long. (So my lay-out won't be
messed up)
How can i detect after submitting if any word
from the field is longer then e.g. 15 chars.
If so, break it at the 14th char, add a dash,
an continue at the next line...
For example:
Thiswordislongerthenfifteencharacters
becomes
Thiswordislong-
erthenfifteenc-
haracters
Any help is greatly appreciated!
Greetings knoak 10 2648
In article <a5*************************@posting.google.com> , knoak wrote: How can i detect after submitting if any word from the field is longer then e.g. 15 chars. If so, break it at the 14th char, add a dash, an continue at the next line...
It depends on what you depend what a word is.
Assuming that every group of characters that is separated by space is
defined as a word.
You could easily lookup with strpos where the spaces occur in a string.
The distance between 2 such positions would be the length of the word.
Or you could use the split function to get all the "words" and use
strlen to determine how long they are.
After this you can use substr to grab parts out of such a word.
More on the functions mentionned above can be found at http://www.php.net/manual -> string functions.
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
I'm sorry,
but since i'm quite new tot PHP i
really don't know where to start.
Can someone help me out a bit further?
Thanks anyway.
Greetings knoakske
if(strlen($word) > 25){
$word = substr($word, 0, 25) . ' ' .substr($word, 25, strlen($word));
} kn******@hotmail.com (knoak) wrote in message news:<a5*************************@posting.google.c om>... Hi there,
I have a form, and i want to prevent words (inserted in a multiline textfield) to become too long. (So my lay-out won't be messed up)
How can i detect after submitting if any word from the field is longer then e.g. 15 chars. If so, break it at the 14th char, add a dash, an continue at the next line... http://in.php.net/wordwrap
--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
I used the upper example,
but now it breaks everything:
thisisoneverylongwor-
danditgetsbroken and-
these are seperate-
words and get broken-
as well
instead of
thisisoneverylongwor-
danditgetsbroken and
these are seperate
words and get broken
as well
so if there's a space, there's no need for a
break with a line.
thanks in advance.
Greetings knoakske
I'm not sure exactly what you want, but I think you want to take a
sentence and check to see if there are any words bigger then a certain
limit. The sentence itself is a string so all the examples break your
sentence up regardless of whether or not there is a really long word.
Is that right?
If it is you just need to use the explode function to break your
sentence up into an array of words. Then cycle through it with a
foreach to find any really long words and use one of the above
examples to break that word when you find it.
knoak wrote: How can i detect after submitting if any word from the field is longer then e.g. 15 chars. If so, break it at the 14th char, add a dash, an continue at the next line...
You have to do this with an regular expression. See preg_replace in the
php manual.
greetings Christian kn******@hotmail.com (knoak) wrote in message news:<a5*************************@posting.google.c om>... Hi there,
I have a form, and i want to prevent words (inserted in a multiline textfield) to become too long. (So my lay-out won't be messed up)
I've been struggling with the same thing. Near as I can figure, the
best way is to use a regular expression, like:
[ \S]{20}
I myself was unsure how to replace the words with broken versions of
the same word. I got some help with long urls here: http://groups.google.com/groups?hl=e....uni-berlin.de
lawrence wrote: I've been struggling with the same thing. Near as I can figure, the best way is to use a regular expression, like:
[ \S]{20}
I myself was unsure how to replace the words with broken versions of the same word.
$target = preg_replace('(\S{20})(?=\S)','\1 ',$target);
enjoy :) kn******@hotmail.com (knoak) wrote in message news:<a5**************************@posting.google. com>... I used the upper example, but now it breaks everything:
thisisoneverylongwor- danditgetsbroken and- these are seperate- words and get broken- as well
instead of
thisisoneverylongwor- danditgetsbroken and these are seperate words and get broken as well
so if there's a space, there's no need for a break with a line.
Usernotes are great resources. You seem to have missed them. Not
sure, if this is what you wanted:
<?php
$text = <<<EOT
thisisoneverylongwordanditgetsbroken and these are seperate words and
get broken as well
EOT;
//Next line logic from http://in.php.net/wordwrap#31342
$text = preg_replace ("/([^\s]{15,})/e", "''.wordwrap('\\1', 14,
'-\n', 1).''", $text);
$text = wordwrap($text, 15, "\n");
echo $text;
?>
BTW, please properly snip and quote other messages.
--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: frizzle |
last post by:
Hi there,
I have data drawn from a mySQL DB. I used to massage the text like
this:
nl2br(wordwrap(htmlentities(stripslashes($entry)), 27, " ", 0))
Now i have a problem: i wanted pasted links...
|
by: Diane Yocom |
last post by:
I realize this may not be the best place to post this, but I was at a loss
as to where to go, so...
I'm trying to merge two separate RTF files (created in Word) into one Word
document. I'd like...
|
by: Gustaf Liljegren |
last post by:
IE does, and I can't remember this used to be a problem in Netscape. I
guess someone in the Mozilla team just came up with a Smart Idea about
the True Semantics of the Hyphen Minus character. :-(...
|
by: Erik K. Schindeldecker |
last post by:
Good Afternoon,
I am exporting a series of datagrids to Microsoft Word, and cannot figure
out how to force a page break between each datagrid. Does anyone know of a
character or command I could...
|
by: dmurray14 |
last post by:
Hey guys,
I'm a C++ newbie here - I've messed with VB, but I mostly stick to web
languages, so I find C++ to be very confusing at times. Basically, I am
trying to import a text file, but I want...
|
by: kevgibbo |
last post by:
Hi,
I'm currently having a problem where a long URL or a line of text with
no spaces will break the design of a webpage, http://
blog.seoptimise.com/2007/01/how-to-add-delicious-and-digg-blog-...
|
by: amitp |
last post by:
Can anyone tell me how can i break a line in MS WORD doc thru VB 6.0 application? I'm replacing the field values with the data from the databse in MS WORD doc. One of my field value is ( "Jan tst....
|
by: newatcoding |
last post by:
Hai friends,
Iam trying to wrap a single word that exceeds a particular length in a text area to be displayed inside a table by using html.
t was suucessfuul, by using word-break:all in IE.
...
|
by: fshsoup |
last post by:
If i write this
$page = 'start';
for (;;) {
include "$page.inc";
}
and inside start.inc I put a "break;" it should work, right? no it
doesn't. And why isn't there any "goto" statement in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |