Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with preg_replace_callback 1

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
Just a little troubleshooting tip: I can't make the callback function used with preg_replace_callback return a blank string (spaces) of certain length. If I try to return a string of say 8 spaces it only returns a string of one space. If I make it return a string of dashes or 'x's of certain length it works fine.
 
It does return as many spaces as you want, but HTML (which I suppose you use to output your PHP) is white-space agnostic, which means that it treats as many spaces as you have as a single space. If you look at your HTML source (with view source in the browser) you will notice that all the spaces are there.

If you really want to, you could use the <pre> element to display this part (pre element will maintain the formatting, that it, it will preserve all the white-space as the original text) or output [tt][ignore]&nbsp;[/ignore][/tt] instead of spaces (those are rendered the same as spaces but they do show up in the browser).

However, the question remains... why would you want to output a bunch of spaces. There probably is a better way of doing it.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Thx, good info. I want to certain replace words in a string with blank spaces of equal size and it ain't happening.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top