Basic Php Proxy

Ladies & Gentlemen,
My Fellow Buddy programmers and would be buddy programmers!

Watching the following youtube tutorial I built a basic php proxy but for some reason it is not working.
Can you guess why ?
The clip uses the deprecated ereg_replace and so I replaced it with preg but no luck.:eek:

https://www.youtube.com/watch?v=P49w0E64MAA

I get a long list of these 2 same errors over and over again.

Warning: preg_replace(): No ending matching delimiter ‘>’ found in C:\xampp\htdocs\e_id\proxy.php on line 9

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\e_id\proxy.php on line 10

And sometimes I get another error instead and all without changing the code:

Parse error: syntax error, unexpected ‘action’ (T_STRING), expecting ‘,’ or ‘)’ in C:\xampp\htdocs\e_id\proxy.php on line 10

proxy.php (238 Bytes)

on the line that has the trailing > try inserting a period and a single quote because there is no value $part>

1 Like

You’ve got two immediate problems with your code:

$part = preg_replace('<img src=','<img src='.$url,$part>');

The >' just inside the function’s closing parenthesis is breaking your code. As John points out, there’s no variable named $part>, and the single quote confuses PHP into thinking that everything that comes after is a string.

The second problem is that you’re not enclosing your regex pattern in delimiters. PHP is seeing the left chevron (<) at the beginning of the string and expecting to find a closing chevron (>) at the end (see http://php.net/manual/en/regexp.reference.delimiters.php) which is why you’re getting those error messages.

To fix this, you need to choose a different delimiter (as the < is part of the string you want to match), so you can do something like this:

$part = preg_replace('/<img src="/', '<img src='.$url, $part);
2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.