SF23103 Posted March 11, 2018 Share Posted March 11, 2018 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 Quote Link to comment https://forums.phpfreaks.com/topic/306800-add-descriptor-text-to-output-in-certain-places/ Share on other sites More sharing options...
Solution requinix Posted March 11, 2018 Solution Share Posted March 11, 2018 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); Quote Link to comment https://forums.phpfreaks.com/topic/306800-add-descriptor-text-to-output-in-certain-places/#findComment-1557077 Share on other sites More sharing options...
SF23103 Posted March 11, 2018 Author Share Posted March 11, 2018 Working great, thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/306800-add-descriptor-text-to-output-in-certain-places/#findComment-1557078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.