473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Wrap() that doesn't split markup

I've been looking into including a system to allow logging of diffs so
users can view different versions of a file and roll it back to an
earlier version. After a lot of faffing with PHP diff functions and
the like I'm thinking that the best way to do it is probably just to
pass the data to the UNIX diff() program to get the diffs for the edit
and use patch() for the rolling back.

Unfortunately there's nothing that stops users entering just a single
long line of markup, and as diff appears to be line-based this means
the generated patches would be very space inefficient. I thought of
running the user input through wordwrap() before committing it but
that's problematic because it can split a HTML tag across lines.

What I need is at least a wordwrap() that takes HTML markup into
account, and I think that maybe some kind of HTML pretty printer would
be better.

Can anyone help with this?
Oct 23 '08 #1
1 1549
On Oct 23, 9:42*am, Gordon <gordon.mc...@ntlworld.comwrote:
I've been looking into including a system to allow logging of diffs so
users can view different versions of a file and roll it back to an
earlier version. *After a lot of faffing with PHP diff functions and
the like I'm thinking that the best way to do it is probably just to
pass the data to the UNIX diff() program to get the diffs for the edit
and use patch() for the rolling back.

Unfortunately there's nothing that stops users entering just a single
long line of markup, and as diff appears to be line-based this means
the generated patches would be very space inefficient. *I thought of
running the user input through wordwrap() before committing it but
that's problematic because it can split a HTML tag across lines.

What I need is at least a wordwrap() that takes HTML markup into
account, and I think that maybe some kind of HTML pretty printer would
be better.

Can anyone help with this?
I had the idea of writing a function that does the following:

1) wordwrap () the passed string
2) find any HTML tags in the result that have a line break in them
3) replace the line breaks with spaces

I tried the following:

function htmlWrap ($string, $width = 75, $break = "\n")
{
$string = wordwrap ($string, $width, $break);
return (preg_replace ('/(<[^>]*)\n([^<]*>)/is', '\1 \2', $string));
}

This doesn't work, it only finds one of the line breaks and then
replaces it with a break and a space.

Input:

This is some <a href="#"
title="link"
target="_self">link</ato some page somewhere

Output:

This is some <a href="#"
title="link"
target="_self">link</ato some page somewhere
Oct 24 '08 #2

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

Similar topics

6
by: leegold2 | last post by:
I have been looking for a php word wrap function. I know there's an official PHP function but I've tried that and many of the functions contributed on that php.net page and none do what I...
8
by: news.pandora.be | last post by:
I want to display a string in a table but when a word in the string is longer then 40 letters it won't wrap. Does anyone know how I can fix this ? Thanx Wannes
44
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with...
6
by: Michael Rozdoba | last post by:
I want to set a background colour on one level of headings, but have their width span only the text & a small amount of padding. I was styling display to inline to achieve this. Then I...
1
by: Simon Wigzell | last post by:
I send HTML formatted emails with links and images in them generated by my asp driven website. Occasionally the image will not appear and the link will not work. By looking at the email at the...
3
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug...
5
by: momo | last post by:
say i have the following table: <table width="500"> <tr> <td width="250">this is the text im concerned with</td> <td></td> </tr> </table> i need the width of the columns to STAY at 250 and...
13
by: Boris | last post by:
Can anyone tell me if Opera 9.5 is behaving correctly when wrapping the word C++, eg: C+ + Opera 9.2 didn't wrap C++. For those who use Opera 9.5 there is a test case at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.