Jump to content
pow

/

Recommended Posts


<?php

$string = "CAPCA P [P] [P] PPP";

echo 'Before : '.$string.' !';

$split = str_split( $string );

foreach( $split as $k => $v )
{
if( $v == "P" )
{
$start = 0;
$finish = 0;

for( $i = $k; $i >= 0; $i-- )
if( $split[$i] == "[" )
{
$start = 1;
break;
}

for( $i = $k; $i < strlen( $string ); $i++ )
if( $split[$i] == "]" )
{
$finish = 1;
break;
}

if( $start != 1 || $finish != 1 ) $split[$k] = "";
}
}

$da = "";

foreach( $split as $k => $v )
$da .= $v;

echo '<br>After: '.$da.' !';

?>


Before : CAPCA P [P] [P] PPP !
After: CACA [P] [P] !

Nu stiu daca este exact ceea ce doresti, dar sper sa iti faci o idee.

Edited by zekstein
  • Downvote 1
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...