1

i want to encode all input values to base64 encoded. So i need some help... My code is:

$check_hash = preg_match_all('/<input type="text" value="(.*?)">/mis', $ays, $hashtweet);

$ays = preg_replace('/<input type="text" value="(.*?)">/', base64_encode($hashtweet[1]), $ays);

echo $ays;

And my page is here: http://www.ceay.biz/test/vkmp3/

But it dont gives me what i want. Can anyone help me?

2
  • what do you expect as a correct value? Commented Jul 18, 2013 at 13:50
  • I am stupid :) I just only change all input values to encoded one Commented Jul 18, 2013 at 13:51

3 Answers 3

2

Use preg_replace_callback to do this (requires php 5.3 for closure)

$ays = preg_replace_callback('/value="(.*)"/', function ($match) {
                          return "value=\"".base64_encode($match[1])."\""; }, $ays);

for pre php 5.3 environments

if (!function_exists("valueReplacer")){
    function valueReplacer ($m){
        return "value=\"".base64_encode($m[1])."\""; 
    }
}
$ays = preg_replace_callback('/value="(.*)"/', "valueReplacer", $ays);
Sign up to request clarification or add additional context in comments.

2 Comments

Parse error: syntax error, unexpected T_FUNCTION in index.php on line 65
closure syntax only works for php 5.3+ ... I will update showing non-closure usage
1

You will need to call preg_replace_callback in order to execute PHP code as replacement:

$ays = preg_replace_callback('/<input type="text" value="(.*?)">/', function ($m) {
                             return base64_encode($hashtweet[1]); }, $ays);

6 Comments

Yes pls provide sample values for $hashtweet and $ays
If you can provide provide sample values for $hashtweet and $ays it will be very helpful.
hashtweet is a array. Here is the hashtweet array ceay.biz/test/vkmp3
Do you want to base64_encode all the elements in the $hashtweet array? Honestly I couldn't understand your problem fully.
yes i want to base64_encode all the elements in the $hashtweet array
|
0

You can check this:

$string = '<input type="text" value="http://cs9-10v4.vk.me/p1/63ec3a36b2eb1c.mp3">';
preg_match('/<input type="text" value="(.*)">/', $string, $matches);
$string = preg_replace('/(<input type="text" value=").*(">)/', "$1".base64_encode($matches[1])."$2", $string);
var_dump($string);

1 Comment

ok, then you need to do a foreach over all values that you have. How you are get the inputs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.