Link to home
Create AccountLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

put line2 in <h6></h6> and line3 in <h1></h1>

<h3>___________________________</h3>
Bob Adams<br/>
Bob real estate<br/>
<h3>___________________________</h3>
Susan<br/>
Susan real estate<br/>
<h3>___________________________</h3>
Mary Adams<br/>
Mary real estate<br/>

Open in new window


<h3>___________________________</h3>
<h6>Bob Adams</h6>
<h1>Bob real estate<h1>
<h3>___________________________</h3>
<h6>Susan</h6>
<h1>Susan real estate</h1>
<h3>___________________________</h3>
<h6>Mary Adams</h6>
<h1>Mary real estate</h1>

Open in new window


line one is a line break
line 2 is the agent name
line 3 is the company name

want to use php, regular expression, to put line2 in <h6></h6> and line3 in <h1></h1>
Avatar of kaufmed
kaufmed
Flag of United States of America image

Try:

$result = preg_replace('#(^.+\n)(.+)<br/>(\r?\n)(.+)<br/>(\r?)#', '(^.+\n)(.+)<br/>(\r?\n)(.+)<br/>(\r?)', $original);

Open in new window

What's the original state of this data?  Is it in a data base?  If your script somehow created the first snippet, it might be easier to just create the second snippet rather than creating the first and then transforming it into the second!
Avatar of rgb192

ASKER

<?php
$original='
<h3>___________________________</h3>
Bob Adams<br/>
Bob real estate<br/>
<h3>___________________________</h3>
Susan<br/>
Susan real estate<br/>
<h3>___________________________</h3>
Mary Adams<br/>
Mary real estate<br/>
';

$result = preg_replace('#(^.+\n)(.+)<br/>(\r?\n)(.+)<br/>(\r?)#', '(^.+\n)(.+)<br/>(\r?\n)(.+)<br/>(\r?)', $original);
echo $result;

Open in new window



'view source' output (almost same as input)
<h3>___________________________</h3>
Bob Adams<br/>
Bob real estate<br/>
<h3>___________________________</h3>
Susan<br/>
Susan real estate<br/>
<h3>___________________________</h3>
Mary Adams<br/>
Mary real estate<br/>

Open in new window



What's the original state of this data?
html in this format
not in my database (yet)
Can you use a string in that way? I thought multi-line strings needed to be in a HEREDOC.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
@kaufmed: Yes, you can define a string that way.  And yes, I agree with you that multi-line string definitions should be HEREDOC (or sometimes NOWDOC) because it makes for much easier punctuation, provides easy variables substitution, etc.
Avatar of rgb192

ASKER

thanks

for a related question

line3 does not always contain the word 'real estate'

https://www.experts-exchange.com/questions/28176914/variation-to-pattern-of-line3.html