Jump to content


Photo

removing slash-n between table tags (SOLVED)


  • Please log in to reply
2 replies to this topic

#1 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 October 2006 - 12:40 PM

I am using xoops, and thier news module insists on replacing slash-n  with br.  The problem is when I try to insert tables into an article I get a huge amount of br.  I am weak on regex, can someone help me with a regex to remove all the slash-n that occure between the start and end table...slash-n...table?

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 09 October 2006 - 02:22 PM

<pre>
<?php
	
	$data = <<<DATA
	<html>
	<body>
	
	before
	
	<table>
		<tr>
			<td>abc</td>
		</tr>
		<tr>
			<td>
1
2
3
			</td>
		</tr>
	</table>
	
	after
	
	</body>
	</html>
DATA;

	function clean_table ($matches) {
		### Remove new lines.
		$table_content = preg_replace("/\r\n/", '', $matches[1]);
		### Clean up space between end/start tags.
		return $table_content = preg_replace('/(?<=>)\s+(?=<)/', '', $table_content);
	}

	echo $data = preg_replace_callback('%(?<=<table)(.+?)(?=/table>)%sm', 'clean_table', $data);

?>
</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 mlavwilson

mlavwilson
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 October 2006 - 04:15 PM

Many thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users