Heyes Posted August 17, 2016 Share Posted August 17, 2016 (edited) New to this... can I use str_replace to replace all instances of a specific word or html tag on a page? I have an html page containing elements produced elsewhere and which I can't remove by simply editing the html. If I've understood str_replace properly, I can add a bit of php to the page and it'll modify things - so in this way I'm hoping to use it to remove some unwanted br tags from code which I can't directly edit. Edited August 17, 2016 by Heyes Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 17, 2016 Share Posted August 17, 2016 Need some more context. When you say "have an Html page", what does that mean if you can't directly edit it? The page is on the screen? And you want to alter it? Very confusing. And how are you going to "add a bit of php to it" if you can't directly edit it? Quote Link to comment Share on other sites More sharing options...
Heyes Posted August 17, 2016 Author Share Posted August 17, 2016 Need some more context. When you say "have an Html page", what does that mean if you can't directly edit it? The page is on the screen? And you want to alter it? Very confusing. And how are you going to "add a bit of php to it" if you can't directly edit it? Thanks. Part of the page is generated by a third-party app - similar to how, for example, Disqus comment system works. (In this particular case, the code comes from an on-site membership script - and to modify I'd have to edit the core... which I don't want to do. So, although I can edit the page, I can't modify all parts... hence the hope for using str_replace to modify things. I now realise that my initial understanding of it was wrong... I thought it would work in a 'global search and replace' way, through a single bit of php positioned somewhere in the code. I now know that I have to position it directly where the replacement is to happen. So - problem sort of solved. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 17, 2016 Share Posted August 17, 2016 I have no idea what you have done. A php function operates in a script on a string that is part of that script, whether it is a variable or some data that is read into that script. How you are doing this on a 'page' is beyond me. But if you are happy... Quote Link to comment Share on other sites More sharing options...
Heyes Posted August 18, 2016 Author Share Posted August 18, 2016 (edited) I have no idea what you have done. A php function operates in a script on a string that is part of that script, whether it is a variable or some data that is read into that script. How you are doing this on a 'page' is beyond me. But if you are happy... As an example, my page html contains <?php echo $frm['elements']['product_id_page-0-0']['htmle'] ?> from a third-party membership app. The code adds br tags which I don't want. By using <?php echo str_replace('<br />', '', $frm['elements']['product_id_page-0-0']['htmle']) ?>, those br tags are removed without the need to modify the core code. There are several instances of similar code in a page, and I add the str_replace to each. When I originally posted my question, I'd mistakenly thought that I could add one str_replace to the whole page and have all br tags removed. I now realise that str_replace has to be added to each element to be modified. Edited August 18, 2016 by Heyes Quote Link to comment 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.