I have a form that outputs a cookie value to a hidden input box for the sake of reporting. The cookie is simply the login email address associated with the website. Sometimes when submitting the form, the email is displayed twice in the input box causing issues with out reporting software.
I figured I could just process the string before it's output to the input box to remove any double instances of a word or remove anything after the .org of our domain (the form is internal so it will always be "ourdomain.org"). I've tried several approaches, but none of the ways I've thought of/tried have worked. A simple character count isn't possible due to the variety of email address lengths. When it displays the email twice, there is no space between them so an explode of an empty space won't work. I've read through most of the PHP manual having to do with string processing and I can't work out how to remove anything after a phrase such as ".org" while still retaining the ".org".
This should work.
<?php
$example="example.orgexample.org";
$example=substr($example,0,stripos($example,'.org')+4);
?>
That will remove anything after the first .org it finds.
Instead of attempting to parse the value in the box, should you not be trying to fix the actual issue, which is the fact that there's something in that box that doesn't belong there?
Try strtstr() as in strstr($sring, '.org', true), but it is best to figure out why the email is repeated in the box, first.
Note: I think strstr() only works with php 5.3 and up. stristr() for case sensitive.