Jump to content

Conditional String Replace


Synapse

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.