tags:

views:

30

answers:

2

Hi!

I want to wrap particular lines in a text mass with <b></b>

  • First line in the text
  • All lines with a previous empty line (eg two newlines before)

I'm using preg_replace with php, but I'm really shitty with regex. Good tutorials are appreciated.

+1  A: 

Try

echo preg_replace('/(?<=\\A|^$\n)(^.+$)/m', '<b>$1</b>', $text);

for example, http://www.ideone.com/1pTwD.

KennyTM
Great! And that link can prove to be very useful as well. Many thanks man! Appreciated
Anders
+1  A: 

In HTML (I'm assuming that's the context) there is no such thing as "lines" in regards to source code, since it's not really possible reliable to determinate how a text wraps (unless you do all the wrapping yourself with <br> or <pre>).

However there is the CSS pseudo-element :first-line that will let you format the first line of an element (for example a paragraph):

p:first-line {
  font-weight: bold;
}
RoToRa
Actually I know how the lines are formated since the text is pasted from an In-Design document. The text need to have the <b> tags in place due to the customers needs.
Anders
Indesign is a Desktop Publishing software. For publishing on paper. **The web is not paper**. Unless you are using a screen shot you can't grantee the text to wrap the same on the web. Do you actually need `b` tags or does the first line need to be bold?
RoToRa