0

I want to replace a string with database function if it exists. I am using str_replace in following way but it doesn't work for me, this is returning $numOne as it was.

function stringreplace($multiple,$numOne){
    $multiple = Multiply;
    $numOne = a_b_cMultiply;
    str_replace($multiple, "abcdfgh('','')::numeric", $numOne);
    return $numOne;
}
5
  • Can you give us the before and after of the value you want to process? :) Commented Dec 1, 2016 at 6:40
  • this is my complete code for this Commented Dec 1, 2016 at 6:42
  • I can't seem to understand your code? What is Multiply? a_b_cMultiply? Commented Dec 1, 2016 at 6:45
  • Multiply is a simple string and a_b_cMultiply is a formula. Actually i want if a_b_cMultiply comes it should be replaced by a_b_cabcdfgh('','') Commented Dec 1, 2016 at 6:48
  • Check the answer of @Rahul :) Commented Dec 1, 2016 at 6:48

1 Answer 1

2

Your code is not correct as you are not storing the result anywhere and also you are returning $numOne which contains the old value . Use this code:

function stringreplace($multiple,$numOne){
$multiple='Multiply';
 $numOne='a_b_cMultiply';
 $num_one = str_replace($multiple,"abcdfgh('','')::numeric",$numOne);
return $num_one;
}
Sign up to request clarification or add additional context in comments.

2 Comments

i got this. and what if i want to add operator like * between a_b_c*abcdgfh('','')
Well in that case change $numOne='a_b_cMultiply' to $numOne='a_b_c*Multiply'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.