Welcome to WebmasterWorld Guest from 54.205.106.138

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg replace question regarding the replacement

     
3:27 am on Jun 12, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 26, 2006
posts: 41
votes: 0


Hi,

I'm trying to tidy up some text, specifically involving users pasting multiple paragraphs of text from Word. I need to check for and remove any \t's used for indenting in Word at the start of paragraphs.

Since I want to focus on the stuff between paragraphs, my regex includes a word boundary at the end. But, what should my replacement be? Here's my code:

$abstract_db = preg_replace('/\n\t+\w+/','\n\n',$abstract_db);

Basically, it looks for a newline followed by a tab that's also followed by a word. It's supposed to replace the newline-tab with newline-newline and hopefully preserve the word (somehow).

The script is now cutting off the first word of the second paragraph, and I know why: the replacement is the problem. But, what should I specify in the replacement part to "retain" the first word? Would \w+ in the replacement know to use the same text as what it found by \w+ in the search?

Is this where $1 and $2 come in?

Thanks!

Glenn

10:26 pm on June 16, 2009 (gmt 0)

New User

5+ Year Member

joined:Jan 21, 2009
posts:18
votes: 0


Found this on a quick google search
[webmasterworld.com...]

seems you may be able to use "str_replace() or ereg_replace() to search the string(s) for tabs and replace them with 3 or 4 no-break-spaces. "

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members