I am having some problems with wordwrapping some text I've pulled from an XML document.
php's wordwrap function returns some lines as too long. Trying to split things by \n and then further split by " " causes problems too, mainly with quotes getting assigned as a single array element unto themselves in the first split (by \n).
wordwrap() seems to be having problems with the quotes specifically also.
Here is the relevant code, XML, and output using php's wordwrap function.
Code
case "TABLE-CONTENT":
$data = wordwrap($data, '60', "\n", 1);
break;
XML
<table-content><b>1982</b>
This $75.5 billion, four-year highway bill increased the federal gas tax by 5 cents per gallon, one penny of which was earmarked for mass transit projects. But the enactment of the legislation didn't come without a fight: President Reagan initially opposed the gas-tax hike,
and opponents waged an ultimately unsuccessful filibuster in the Senate.
<b>1987</b>
President Reagan vetoed this $87.6 billion, five-year highway bill, claiming it was filled with reckless spending and pork. Congress, however, overrode the president's veto and passed the legislation anyway. Despite Reagan's rhetoric, the bill represented the smallest funding increase for any highway bill of the past 20 years.
<b>1991</b>
With most of the U.S. interstate system completed, Congress began to turn its attention from roads to transit. This $155 billion, six-year highway bill?..called the Intermodal Surface Transportation Efficiency Act, or ISTEA?..gave states and localities the flexibility to use their highway funds for transit, bike paths, and pedestrian walkways.
<b>1998</b>
This highway bill, the Transportation Equity Act for the 21st Century, or TEA-21," erected a budgetary "firewall" around the
Highway Trust Fund, ensuring that Congress could spend money going into the fund only on transportation. Costing $218 billion over six years, it was?..until now?..the largest public works bill in U.S. history.
</table-content>
</table>
<table>
<table-title>The Drive to Find More Dough</table-title>
<table-hed>Finding new revenue is one of the biggest challenges Congress faces in crafting this year's highway bill. The fiscal 2004 budget resolution, approved in April, allows for a $273 billion highway bill. But it leaves the door open to an even bigger bill, so long as members can find ways to pay for it. In the House, leaders of the Transportation and Infrastructure Committee are calling for a $375 billion
highway bill, while key Senate committees are seeking a $311.5 billion package. Here are the leading proposals in each chamber to raise additional revenue:</table-hed>
<table-content><b>House Transportation and Infrastructure Committee</b>
?.? Crack down on fuel-tax evasion (for example, by truckers who illegally use jet fuel, which is cheaper).
?.? Eliminate the 5.2-cent-per-gallon federal tax exemption that encourages the use of ethanol-based fuel. (The federal tax on ethanol is currently only 13.2 cents per gallon, not 18.4 cents, as it is for gasoline.) Also, divert into the Highway Trust Fund the 2.5 cents per gallon of the ethanol tax that's now devoted to general revenues.
?.? Tap more of the balance in the Highway Trust Fund, plus the interest on this balance.
?.? Increase the 18.4-cent-per-gallon federal gas tax by 5 cents, which would adjust this tax to account for inflation since the last hike,
in 1993. And permanently tie the gas tax to the Consumer Price Index.
<b>Revenue:</b> $375 billion in contracting authority
<b>Senate Finance Committee</b>
?.? Also would crack down on fuel-tax evasion.
?.? Also would eliminate the 5.2-cent-per-gallon ethanol tax exemption and divert 2.5 cents in ethanol taxes to the Highway Trust Fund.
?.? Transfer 2.36 cents of the 2.86 cents per gallon of the federal gas tax that's set aside for transit and devote it to highways. In
addition to the half-cent left for transit, create a bonding proposal to finance and grow transit spending.
</table-content>
Output
<table-content>
<pre><b>1982</b>
This $75.5 billion, four-year highway bill increased the
federal gas tax by 5 cents per gallon, one penny of which
was earmarked for mass transit projects. But the enactment
of the legislation didn't come without a fight: President Reagan initially opposed
the gas-tax hike, and opponents waged an ultimately
unsuccessful filibuster in the Senate.
<b>1987</b>
President Reagan vetoed this $87.6 billion, five-year
highway bill, claiming it was filled with reckless spending
and pork. Congress, however, overrode the president's veto and passed the legislation anyway. Despite Reagan's rhetoric, the bill represented the smallest funding
increase for any highway bill of the past 20 years.
<b>1991</b>
With most of the U.S. interstate system completed, Congress
began to turn its attention from roads to transit. This $155
billion, six-year highway bill -- called the Intermodal
Surface Transportation Efficiency Act, or ISTEA -- gave
states and localities the flexibility to use their highway
funds for transit, bike paths, and pedestrian walkways.
<b>1998</b>
This highway bill, the Transportation Equity Act for the
21st Century, or TEA-21," erected a budgetary "firewall" around the Highway Trust Fund, ensuring that Congress could
spend money going into the fund only on transportation.
Costing $218 billion over six years, it was -- until
now -- the largest public works bill in U.S. history.
</pre></table-content>