rgb192
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/>
<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>
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>
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!
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;
'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/>
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
@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.
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
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
Open in new window