Jump to content
SF23103

Add descriptor text to output in certain places

Recommended Posts

Hello,

 

I'm trying to deal with a not-so-friendly API.  Instead of XML or JSON, it outputs content in html.  Here is an example:

===================================================<br/>
10:05 some text here 1789210011<br/>
===================================================<br/>

I have used str_replace to change the "======" line to a horizontal line, which worked great.

 

What I would like to do is add "Time:" before the displayed time, "Description:" before the 'some text here', and "ID Number:" before the 10 digit number.

 

Fortunately the output is formatted consistently, but is there a way to add what I want before and after all "##:##" and before the 10 digit number?

 

Of course it would be so much easier if this was XML, but it's not, and I have no control over what's being pushed to me. grrrrrr

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Regex would be an easy way to handle this.

$line = preg_replace('#^=+<br/>$#', '<hr>', $line);
$line = preg_replace('#^(\d\d:\d\d) (.*?) (\d{10})<br/>$#', 'Time: $1 - Description: $2 - ID Number: $3', $line);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.