Jump to content


Photo

Insert   into empty td tags


  • Please log in to reply
3 replies to this topic

#1 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 02 August 2006 - 01:51 AM

I tried writing something to do theis, but you know how it is when you don't have the knowledge. A www search hasn't found anything, so would anyone care to share a preg expression with me?

Just in case a result is empty, the CSS styling in IE needs a non breaking space in the td cell.

Search for td tags containing only whitespace/newline chars.

It will be used like this:

function assemble_page(){
return preg_replace('search','replace','results from the object methods');
}
// end function


Cheers.
Experience is something you get just after you need it.

#2 effigy

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

Posted 02 August 2006 - 02:15 AM

If this is your code, write it to output the nbsp's for you; otherwise:

<pre>
<?php

	$tests = array(
		'<td>leave me alone</td>',
		'<td align="left">leave me alone too</td>',
		'<td style="color:red"></td>',
		'<td>i need to be closed',
		'<td></td>',
		'<td>	</td>',
		'<td>
		</td>'
	);

	foreach ($tests as &$test) {
		echo htmlspecialchars(sprintf('%-40s -> ', $test));
		echo htmlspecialchars(preg_replace('%<(td)([^>]*)>\s*</\1>%i', '<\1>&nbsp;</\1>', $test));
		echo '<br />';
	}
?>
</pre>

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

#3 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 02 August 2006 - 02:42 AM

Exactly what I needed, thanks!
Experience is something you get just after you need it.

#4 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 02 August 2006 - 08:09 AM

Updated version that retains the classNames:

<?php

$pageContent .= preg_replace('%<(td)([^>]*)>\s*</\1>%i', '<\1\2>&nbsp;</\1>', show_message().$passedContent.$this->content);

?>

Cheers
Experience is something you get just after you need it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users