Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $content = '<img src="https://img.fotofaze.com/img/ikan.jpg"><br>'.
- '<img src="https://img.fotofaze.com/img/kucing.jpg"><br>'.
- '<img src="https://img.fotofaze.com/img/harimau.jpg"><br>';
- function img_replace_callback($matches) {
- $url = $matches[1];
- echo $url;
- $domains = array(
- "img01.fotofaze.com",
- "img02.fotofaze.com",
- "img03.fotofaze.com",
- "img04.fotofaze.com",
- "img05.fotofaze.com"
- );
- $ori_host = parse_url($url, PHP_URL_HOST);
- $index = crc32($url) % count($domains);
- if ($ori_host == 'img.fotofaze.com') {
- return 'src="'.str_replace('img.fotofaze.com', $domains[$index], $url).'"';
- }
- return 'src="'.$url.'"';
- }
- $counter = 0;
- function replace_img_domain($text) {
- global $counter;
- $text1 = preg_replace_callback(
- '|src="(^"*)"|' ,
- 'img_replace_callback',
- $text,
- $counter
- );
- return $text1;
- }
- echo '<pre>'.$counter."\n";
- var_dump(replace_img_domain($content));
- echo '</pre>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement