Obfuscate email address on php [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to obfuscate or cover an email address on PHP.
For this, i have the next code.
<td>
<p class="list-item-heading"><small><?= $row->email ?></small></p>
</td>
Where $row->email is
realname_x123#gmail.com
.
I need to show this as
r*al****_x*2*#gmail.com
I need to replace with * ALWAYS the same parts of the string, not randomly because it will be shown on a list, maximun of 5 or 6 characters visible.
Anytips? I've tried with strpos, and str_replace with no success.
EDIT:
IF this cannot be do. It will be usefull also, for example, to only leave 3 chars from the beggining.
rea***********#gmail.com
I've found a workaround that suits for me.
<?php
function hideEmail($email)
{
$mail_segments = explode("#", $email);
$mail_segments[0] = substr($mail_segments[0], 0, 1) . str_repeat("*", strlen($mail_segments[0]) - 2) . substr($mail_segments[0], -1);
$pos = strpos($mail_segments[1], '.');
$mail_segments[1] = substr($mail_segments[1], 0, 1) . str_repeat("*", strlen($mail_segments[1]) - $pos+1) . substr($mail_segments[1], $pos-1);
return implode("#", $mail_segments);
}
?>

function mailObfuscate($mail) {
//every second character replace with *
$mail = explode('#',$mail);
$array = str_split($mail[0]);
$control = 0;
$ret = '';
foreach ($array as $char) {
if ($control == 0) {$ret .= '*'; $control++;} else {$ret .= $char; $control=0;}
}
return $ret.'#'.$mail[1];
}

Related

Given a string that is a range of excel cells 'A1:F1' how would one go about interpolating this range in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I would like to fill this 'A1:F1' out to either an array or a string such that it now equals array {A1, B1, C1, D1, E1, F1} or "A1:B1:C1:D1:E1:F1"
Does anyone have an efficient idea on how to do this?
Thanks.
This is one possible solution. It works in two dimensions. As can be seen in the output, it works column by row, to reverse that simply requires changing the order of the two for loops.
function split_range($range) {
list($start_cell, $end_cell) = explode(':', $range);
if (!preg_match('/^([A-Z]+)(\d+)$/', $start_cell, $start) || !preg_match('/^([A-Z]+)(\d+)$/', $end_cell, $end)) return array();
$cells = array();
for ($c = $start[1]; str_pad($c, strlen($end[1]), " ", STR_PAD_LEFT) <= $end[1]; $c++) {
for ($r = $start[2]; $r <= $end[2]; $r++) {
$cells[] = "$c$r";
}
}
return $cells;
}
echo implode(':', split_range("A1:F1")) . "\n";
echo implode(':', split_range("A1:A6")) . "\n";
echo implode(':', split_range("B2:D4")) . "\n";
echo implode(':', split_range("Q3:AB4")) . "\n";
Output:
A1:B1:C1:D1:E1:F1
A1:A2:A3:A4:A5:A6
B2:B3:B4:C2:C3:C4:D2:D3:D4
Q3:Q4:R3:R4:S3:S4:T3:T4:U3:U4:V3:V4:W3:W4:X3:X4:Y3:Y4:Z3:Z4:AA3:AA4:AB3:AB4
If I don't misunderstood your question, then is one solution to achieve what you said on your question using php. But let me know if I am on wrong track :)
<?php
$str = 'A1:F1';
$arr = explode(":",$str);
$start = $arr[0];
$end = $arr[1];
$range = range($start[0],$end[0]);
$func = function($value) use ($start){
return $value.$start[1];
};
$result = array_map($func,$range);
echo "{".implode(',',$result)."}";
echo PHP_EOL;
echo implode(':',$result);
?>
Output:
{A1,B1,C1,D1,E1,F1}
A1:B1:C1:D1:E1:F1
DEMO: https://3v4l.org/iDsGe

How To Display Random Results in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im trying to display 2 or more unique random results from a text file, How do I do that please?
But I need unique results and not 2 or more of the same.
Currently using this code, but it only returns 1 random result:
<?php
$text = file_get_contents('flatFileDB.txt');
$textArray = explode("\n", $text);
$randArrayIndexNum = array_rand($textArray);
$randPhrase = $textArray[$randArrayIndexNum];
?>
<?php echo $randPhrase ?>
I would use something like that
shuffle($textArray);
echo $textArray[0];
echo $textArray[1];
http://php.net/manual/tr/function.shuffle.php
You can give a shot to this also. Code is not tested. I am collecting the used into an array, and check, is that used before.
$text = file_get_contents('flatFileDB.txt');
$textArray = explode("\n", $text);
$used = array();
$countOfRandoms = 2;
$randoms = array();
$i = 1;
do {
if ($countOfRandoms == $i) {
break;
}
$randArrayIndexNum = array_rand($textArray);
if (in_array($randArrayIndexNum, $used)) {
continue;
}
$used[] = $randArrayIndexNum;
$random = $textArray[$randArrayIndexNum];
$i++;
} while (true);

Parse url and choose specific number with php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How is it possible to choose a specific word/s or number/s from a link with php. I have the following urls where I want to choose only the rss number. Have been trying to use preg_match and preg_replace to no avail unfortunately.
<link><![CDATA[http://www.domain.com/league/news/newsid=21898248704.html?rss=2148704+hakska+iwumao+oioqp+badge+water]]></link>
<link><![CDATA[http://www.domain.com/rugby/video/ball/index.html?rss=2133483+water+none+respective+all+sat's+report]]></link>
As you can see the urls are not the same but both have rss=XXXXXX. My aim is to insert the number after "rss=" into the database.
Would appreciate if anyone can give me a tip of how to do this.
Like this ?
<?php
$link = '<link><![CDATA[http://www.domain.com/league/news/newsid=21898248704.html?rss=2148704+hakska+iwumao+oioqp+badge+water]]></link>';
preg_match('/rss=([0-9]+)/', $link, $matches);
echo $matches[1]; // returns 2148704
?>
$url = "http://www.example.com/foo.php?rss=9001+asdf";
$res = "";
$i = 0;
if (($i = strpos($url, 'rss=')) !== false) {
$res = substr($url, $i + 4); // +4 because the length of 'rss=' is 4, we just want the value
if (($i = strpos($res, '+')) !== false) { // $res contains +, cut that off
$res = substr($res, 0, $i);
}
// res has a value
echo $res;
} else {
// res has no value
}
Example
$link = '';
preg_match('/rss=([0-9]+)/', $link, $matches);
echo $matches[1]; // returns 2148704
Worked fine. Thanks a lot Phantom!

Get part of string in PHP without explode [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have the following string
$s = "hellomyname";
$result = ...
How can I get the "my" out of this the fastest way possible?
You have to find the position of ((my)) in your string with strpos() function and then fetch the word with substr().
here is an example:
<?php
$s1 = 'laldkfjamydnadjacv zdvzkv';
$pos = strpos($s1, 'my');
echo 'First Position---> ' . $pos;
$my1 = substr($s1, $pos, 2);
echo '<br /> this is result---> ' . $my1;
//second test
$s2 = 'hellomyname';
$pos2 = strpos($s2, 'my');
echo '<br />Second position---> ' . $pos2;
$my2 = substr($s2, $pos2, 2);
echo '<br />this is second result---> ' . $my2;
?>
and this is result:
First Position---> 8
this is result---> my
Second position---> 5
this is second result---> my
I think you're looking for substr($s, 5, 2).
Explode (Delimiter, text)
In your case can use:
$result = explode('my', 'hellomyname'); // array([0] => 'hello', [1] => 'name');
If you need get the last value you can put end():
$result = end(explode('my', 'hellomyname')); //name
Reference
http://www.php.net/manual/pt_BR/function.explode.php
http://us1.php.net/end

string cutter php script not work properly [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am using below script for cut my strings.
$titlex = strip_tags($title);
if (strlen($titlex) > 35) {
// truncate string
$stringCutx = substr($titlex, 0, 35);
// make sure it ends in a word so assassinate doesn't become ass...
$titlex = substr($stringCutx, 0, strrpos($stringCutx, ' ')).'...read MOre';
}
but its not work well in all conditions likes if string have 2 white spaces it not work default it some time cut those string or some time not. and if string don't have any white space it not cut string however if it Long storing but its not cut.. I am try to solve this issue but not found any solution because of experience. how i solve this issue ?
I'd go for wordwrap
$titlex = strip_tags($title);
$len=35;
if (strlen($titlex) > $len) {
$stringCutx=explode("\n",wordwrap($titlex,$len,"\n",true),2);
$stringCutx=$stringCutx[0].'...read MOre';
}
$titlex = strip_tags($title);
if (strlen($titlex) > 35) {
$stringCutx = substr($titlex, 0, 35);
if (strlen($stringCutx) >= 35 && isset($title[$titlex])) {
if ($title[$titlex] != ' ') {
$pos = strpos($title, ' ', 35);
if ($pos == 0) {
$res = $text;
} else {
$temp = substr($title, 35, $pos - 35);
$res = $res.$temp.'...read MOre';
}
}
}
}

Categories