Jump to content

Add descriptor text to output in certain places


Go to solution Solved by requinix,

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

 

 

 

 

 

 

  • Solution

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);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.