I am trying this bit of code to remove the xx from the beginning on the required fields i.e. xxBarcode.
foreach($_POST as $key => $value) {
if ((preg_match_all ("|^[xx]|","$key",$out))){
$keynew = substr_replace($key,"",+0 , +2);
$_POST[$key] = $keynew;
echo 'THE NEW KEY '.$_POST[$key].'<br>'; // this is fine and displays Barcode
}
}
echo '<pre>'; print_r($_POST); echo '</pre>'; // this is still showing xxBarcode
I just can’t see what is going wrong or why print_r is not showing the new key values.
If anyone can point out what I am doing wrong,that would be great.
You nearly had it already but the one line $_POST[$key] = $keynew; should be like the one I posted. Then you’ll probably want to get rid of the ‘xxBarcode’ type keys with unset($_POST[$key]); right after, or just make a new array for the new keys instead of putting them into POST.
As a side note, instead of all the regex I’d do something like
if (0 === strpos($key,"xx")) {
$keynew = substr($key,2);
Awesome, I have been trying many things.
All I had to do was look at SilverBulletUK’s, code and it was crystal clear and it was as simple as changing
$_POST[$key] = $value;
To
$_POST[$keynew] = $value;
in the loop and yes I ended up with xxBarcode and Barcode with my way of doing it.
Thanks heaps, your code examples look a lot better than my clunky stuff and I learned more than I bargained for.
Cheers
Loren
Edit:
QMonkey, I just saw a similar example of strpos and was wondering how it would work for me, awesome timing