473,499 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wordwrap with a twist?


I need to wrap text with a negative indent, that is this:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

gives this:
Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo
consequat.
Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id
est laborum.

Is there a clever way to do this? All I can come up with is to parse
painfully the strings word-by-word and count the characters, which on a
long list (hundreds, possiblyly thousands of lines) is quite resource-
intensive.

(the indent can be tabs or spaces, it does not matter)

Thanks,

Pierre
--
Pierre Jelenc | New on Home Office Records: Ethan Lipton
| www.homeofficerecords.com www.ethanlipton.com
The Gigometer | Pepper Of The Earth: the HO blog
www.gigometer.com | www.homeofficerecords.com/blog
Jul 17 '05 #1
6 1920
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:
gives this:
Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo
consequat.


try this....
http://au.php.net/manual/en/function.wordwrap.php
then do a search/replace for each "\n" replacing it with "\t\n".

havent tried it, but should be fairly simple.... i think.

--
dance with children in the rain

Jul 17 '05 #2
Disco Octopus wrote :
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:
gives this:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.


try this....
http://au.php.net/manual/en/function.wordwrap.php
then do a search/replace for each "\n" replacing it with "\t\n".


..... or rather.....

do a search/replace for each "\n" replacing it with "\n\t".

--
dont pick your nose if it is sore

Jul 17 '05 #3
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:
gives this:
Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.


OK. i tried this....

<?php

$v_1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$v_1 = wordwrap ( $v_1, 50, "\n", 1);
echo "<pre>\n";

// do some kinda loop here to get your parapraphs/sentences out of each
string.

$v_1 = str_replace ( "\n", "\n\t", $v_1);
echo $v_1;

// end some kinda loop
echo "</pre>\n";
?>

--
if the oil light is on, dont think it will just go away

Jul 17 '05 #4
Disco Octopus <di**********@yahoo.com> writes:
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:

*negative indent* is the crucial phrase.
$v_1 = str_replace ( "\n", "\n\t", $v_1);
echo $v_1;


All this does is shift the first wrapped line to the left, however it is
still only the same size as the others' text, while it should be longer:

XXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZ

The solution turns out to chop off the start of the text, wordwrap and add
the tabs, then add back the chopped piece at the start of line one.

Pierre
--
Pierre Jelenc | New on Home Office Records: Ethan Lipton
| www.homeofficerecords.com www.ethanlipton.com
The Gigometer | Pepper Of The Earth: the HO blog
www.gigometer.com | www.homeofficerecords.com/blog
Jul 17 '05 #5
Pierre Jelenc wrote :
Disco Octopus <di**********@yahoo.com> writes:
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:


*negative indent* is the crucial phrase.
$v_1 = str_replace ( "\n", "\n\t", $v_1);
echo $v_1;


All this does is shift the first wrapped line to the left, however it is
still only the same size as the others' text, while it should be longer:

XXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZ

The solution turns out to chop off the start of the text, wordwrap and add
the tabs, then add back the chopped piece at the start of line one.

Pierre


Not sure what you mean by *negative indent*

.... but I did want to give it another go anyway. this is what I came up
with....

<?php

$v_indent = 4; // the size of the indent in characters
$v_wrapat = 50; // the wrap line at size
$v_nl = "\n";

$v_full_story = "Lorem ipsum dolor sit amet, consectetur adipisicing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.";

$v_paragraphs = explode ( $v_nl, $v_full_story);
echo "<pre>" . $v_nl;

reset($v_paragraphs);
while (list($key, $v_paragraph) = each($v_paragraphs)) {

$v_firstline = substr ( $v_paragraph, 0, $v_indent + $v_wrapat);

$v_restlines = substr ( $v_paragraph, $v_indent + $v_wrapat);

$v_restlines = wordwrap ( $v_restlines, 50, $v_nl, 1);
echo $v_firstline . $v_nl;
$v_restlines = str_replace ( $v_nl, $v_nl . " ",
$v_restlines);
echo " " . $v_restlines;
}

echo $v_nl . "</pre>" . $v_nl;
?>

--
if the oil light is on, dont think it will just go away

Jul 17 '05 #6
Disco Octopus wrote :
Pierre Jelenc wrote :
Disco Octopus <di**********@yahoo.com> writes:
Pierre Jelenc wrote :
I need to wrap text with a negative indent, that is this:


*negative indent* is the crucial phrase.

and then i thought about it, and got this...

*Attempt 234* (and counting)

i think this will do the trick.
<?php

$v_indent = 3;
$v_wrapat = 40;
$v_nl = "\n";
$v_dent = "";

$v_i = 0;
while ($v_i < $v_indent) {
$v_dent = $v_dent . " ";
$v_i++;
}

$v_full_story = "This will wrap the first line of each paragraph at
character $v_wrapat or earlier. Each subsequent line will be wrapped
at character $v_wrapat less $v_indent. The \"less $v_indent\" takes
into account the extra characters placed before each of the lines for
the actual indent.
This will wrap the first line of each paragraph at character $v_wrapat
or earlier. Each subsequent line will be wrapped at character
$v_wrapat less $v_indent. The \"less $v_indent\" takes into account
the extra characters placed before each of the lines for the actual
indent.";

$v_paragraphs = explode ( $v_nl, $v_full_story);
echo "<pre>" . $v_nl;

reset($v_paragraphs);
while (list($key, $v_paragraph) = each($v_paragraphs)) {

$v_firstline = wordwrap ( $v_paragraph, $v_wrapat, $v_nl, 1);
$v_temp = explode ( $v_nl, $v_firstline);
$v_firstline = $v_temp[0];

$v_len = strlen ($v_firstline);
$v_restlines = substr ( $v_paragraph, $v_len + 1);

$v_restlines = wordwrap ( $v_restlines, $v_wrapat - $v_indent -
1, $v_nl, 1);
echo $v_firstline . $v_nl;
$v_restlines = str_replace ( $v_nl, $v_nl . $v_dent,
$v_restlines);
echo $v_dent . $v_restlines;
}

echo $v_nl . "</pre>" . $v_nl;
?>

--
if you pay for your gym memebership, use it

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2674
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
0
1243
by: Richard Back | last post by:
Hi, I would like to print the contents of a textbox to a printer, and for the text to wordwrap. The text could be more than one pages worth so I need to track the pages. I can get it to...
0
2440
by: Mike | last post by:
Hi All, I mistakenly just posted this to the VB group. Sorry for the cross-post. I am working with a textbox in C# which pulls a set of lines (stored in the database as text_type,...
1
1884
by: louise raisbeck | last post by:
Hi there, I create a report online with basically a dump of loads of tables. One of them has 27 columns and as such it ignores the datagrid.width property and goes right along the screen in a...
2
2810
by: yxq | last post by:
Hello, The length of Tooltip string is not fixed, how to wordwrap according to width size? Where to find a function to return Multi-lines string from a long string? Thank you
1
2687
by: Cesar Ronchese | last post by:
Hi! I'm using a DataGridView to show a datatable that have many columns. When it displays data, the lines are applying wordwrap in some cells, because the grid is too wider to page. I'm...
4
11684
by: the_mikado | last post by:
Hi, If this has been answered before I am sorry, but I want to wordwrap the items in a listbox so I dont have to use the horizontal scroll bar. Is this possible? if so how can it be done? ...
0
1458
by: Harvey Triana | last post by:
Hi -- How to do a GridView without wordwrap ? <HT/> Thanks
4
4414
by: Chuckhriczko | last post by:
I need to possibly twist an image on the z axis in Javascript. Here is the deal. We have sliding effects and so forth for our company's website but there is too much sliding. We want something more...
0
7134
marktang
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,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
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,...
0
7225
jinu1996
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...
1
6901
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...
0
7392
tracyyun
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...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.