Synapse Posted October 5, 2021 Share Posted October 5, 2021 Hi Folks, My website currently sets $model variable as follows: $model = $_POST['model']; I am trying to find a way to replace a string only if it equals a certain value such as IF $_POST['model'] = "HP OfficeJet Pro:9015e" then replace that with "HP9015e" There may be need for some more replace options in the future so I would like to ensure whatever direction I take with this, that it has the ability to add some more. Is anyone aware of any such examples of what I am trying to achieve? Most of my problem is I don't know what I am searching for 🙂 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/313870-conditional-string-replace/ Share on other sites More sharing options...
requinix Posted October 5, 2021 Share Posted October 5, 2021 Fixing values like that in code is not the answer. Where is that "HP OfficeJet Pro:9015e" value coming from in the first place? Why is it not the "HP9015e" value that you actually want? Quote Link to comment https://forums.phpfreaks.com/topic/313870-conditional-string-replace/#findComment-1590689 Share on other sites More sharing options...
Synapse Posted October 5, 2021 Author Share Posted October 5, 2021 1 minute ago, requinix said: Fixing values like that in code is not the answer. Where is that "HP OfficeJet Pro:9015e" value coming from in the first place? Why is it not the "HP9015e" value that you actually want? Thank you for the reply requinix. I couldn't agree more, the value is coming from a selected line item on a table which I have no control over Quote Link to comment https://forums.phpfreaks.com/topic/313870-conditional-string-replace/#findComment-1590692 Share on other sites More sharing options...
Barand Posted October 5, 2021 Share Posted October 5, 2021 Having the item name POSTed to your page can also be a nightmare. Users are not renowned for consistency. So many possible variations HP OfficeJet Pro:9015e OfficeJet Pro 9015e HP Pro:9015e HP Officejet 9015E HP Pro 9015 e HP 9015e HP9015e Better by far if you can get a product ID. Quote Link to comment https://forums.phpfreaks.com/topic/313870-conditional-string-replace/#findComment-1590693 Share on other sites More sharing options...
Synapse Posted October 5, 2021 Author Share Posted October 5, 2021 1 hour ago, Barand said: Having the item name POSTed to your page can also be a nightmare. Users are not renowned for consistency. So many possible variations HP OfficeJet Pro:9015e OfficeJet Pro 9015e HP Pro:9015e HP Officejet 9015E HP Pro 9015 e HP 9015e HP9015e Better by far if you can get a product ID. Thanks both Barand and Requinix, I think I will revert back to the person in charge of the DB that fills the table and see if they have ideas for cleaning it up as it is much better to have it correct from the get-go and not cleaning it up as I go. Quote Link to comment https://forums.phpfreaks.com/topic/313870-conditional-string-replace/#findComment-1590697 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.