replacing string from text

i have any text. i want to delete strings from this text.strings will start with abc and finish with xyz.i want to delete these strings.

i mean i want to delete

abc64643643634643634634xyz
abc64353343634634l_6jl43_k6jlk34j436xyz

i know the function preg_replace but i don't have any idea with patterns.

in php please
btocakciAsked:
Who is Participating?
 
SissonConnect With a Mentor Commented:
preg_replace("/abc(.*?)xyz/", "$1", $string);
0
 
ncooCommented:
Try:

<?php
$string = 'abc64353343634634l_6jl43_k6jlk34j436xyz';
$newstring = preg_replace('/^abc([a-zA-Z0-9_]*?)xyz$/i', '', $string);
echo $newstring;
?>
0
 
ncooCommented:
This will replace abc * xyz anywhere it appears in a string:

<?php
$string = 'yghjabc64353343634634l_6jl43_k6jlk34j436xyzytfghj';
$newstring = preg_replace('/abc([a-zA-Z0-9_]*?)xyz/i', '', $string);
echo $newstring."<br/>";//outputs yghjytfghj
?>

This will only replace abc * xyz where abc is at the start and xyz at the end
<?php
$string = 'abc64353343634634l_6jl43_k6jlk34j436xyz';
$newstring = preg_replace('/^abc([a-zA-Z0-9_]*?)xyz$/i', '', $string);
echo $newstring; //outputs nothing
?>
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
btocakciAuthor Commented:
sorry but it didn't work.i want to delete this string

<A onclick="MyWindow=window.open('pencere.php?link=178','Mywindow','toolbar=no,directories=no,top=100,left=100,status=no,scrollbars=yes,resizable=no,width=250,height=200');" href="#">

i mean i want this <A onclick="MyWindow".....whatever.....href="#">

and i use this code for this.

$bilgi = preg_replace('/<A onclick=\"MyWindow\"([a-zA-Z0-9_]*?)href=\"#\">$/i', '', $bilgi);

i echo $bilgi.but it is still same.
0
 
btocakciAuthor Commented:
$x = preg_replace('/<A onclick=([a-zA-Z0-9_]*?)href="#">/i',"",$bilgi);

this didn't work too
0
 
btocakciAuthor Commented:
thanks this worked

$bilgi = preg_replace('/<A onclick=(.*?)href="#">/',"$2",$bilgi);

but i dont know why i wrote $2 and how does it work :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.