0

i want to replace '<' and '>' sign in string. e.g

$str = 'if x<y and y>z';
echo str_replace( '<', 'something', $str ) . "\n";

this give the following result

if xsomethingy and y>z

my question is how can i replace '>' to text 'something'

0

3 Answers 3

2
str_replace( array('<', '>'), 'something', $str )

is a possibility, see manual

Sign up to request clarification or add additional context in comments.

3 Comments

how should i replace '>' to other text not specifically 'something'
and '<' should be replace with 'something'
thanks RC i have done this by using str_replace(array('<','>'),array('&lt','&gt', $str) and this work for me
0

preg_replace(/[<>]/g, 'something', $str)

You need to study some PHP yah
http://php.net/manual/en/function.preg-replace.php

1 Comment

how should i convert '<' to &lt and '>' to &gt in the same example
0

check out preg_replace()

Documentation is here http://php.net/manual/en/function.preg-replace.php

example would be preg_replace('/[<>]/', 'something', $str);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.