Forum Moderators: coopster
I have come to a minor problem for some, but to a hell of a problem for me.
One typical form submits some data to a page. All data are saved to db at first and show to the user later on.
Now the tricky part. If user is not logged in, he should not see some of the data... I will have him see somethig like: Phone Number: N/A
I check the login function and if I find him not logged in I simply change the data I show on screen.
For this purpose I need to use the preg_replace function.
In most cases I inject two sets of (@@) in the strings I plan to change, and using the preg_replace I intent to chage the data between the @@'s into the N/A or anything else i feel like for that data.
So what is a simple syntax for such an expression? I managed to inject the set of @@ to the various string, and I also managed to change one type of field into the N/A part. But for all the rest I failed.
I have no knowledge on regular expressions and any help is appreciated.
For anyone that may find it usefull, the pattern I use for email conversion is this: [\w-\d]+@[\w-\d]+(\.[\w-\d]+)*.
Also the above pattern leaves the @@ in the middle of the string. How can I remove them?
I try using a simpel pattern like: ^(@@(.*)@@)*$ but it failed.
Thanks in advanced
the above is over simplified but you could see where I go with that.
Another word check user status and display content accordingly
<pre>
<?php
$subject = '
Here is some data:
First Name: John
Last Name: Doe
Password: @@secret@@
Phone: @@555-1212@@
Email: @@name@example.com@@
';
print $subject;
$pattern = "/(@@.*@@)/";
$replacement = 'N/A';
print preg_replace($pattern, $replacement, $subject);
?>
</pre>
But for some reason, the final result is:
First Name: John
Last Name: Doe
Password: @@N/A@@
Phone: @@N/A@@
Email: @@N/A@@
where N/A is the text I use to replace the specific fields.
I will have another go this weekend with the regular expressions and see what i can come up with.