Jump to content

locate,edit,replace text


Kizzie33

Recommended Posts

I know you can do ereg_replace(); to find and replace a specific word but i wont to know if i can edit a segment if i dont know what the middle is. I dont know what the middle is but i know whats at the start a middle

E.g.

src="http://what.ever/goeshere"

src=" and " will never change but whats in the middle will change is there a piece of code that will locate the src" and edit whats in the middle and stop at the next " ??

 

Thankyou ! And i hope i explained it in the least confusing way, im forever over complicating things

Link to comment
https://forums.phpfreaks.com/topic/182698-locateeditreplace-text/
Share on other sites

I need to do what i put to be honest, im building a basic proxy server

the I need to change all the herf's

So it will be herf="/help/index.php"  - for example

Now herf=" will never change an it will always end with "

And once i have the /help/index.php i wont to encrypt it with any basic encryption key which can then be decrypted later.

 

Again sorry if i over complicated it

Thankyou !!

I'm gonna assume you mean href (because herf doesn't exist), do you mean something like this:

 

$text = <<<TEXT
<a href="/help/index.php">Something</a>
Blah Blah Blah
<a href="/help/something.php">Something</a>
TEXT;

$text = preg_replace('~href="([^"]+)~', "href=\"http://www.somesite.com$1", $text);
echo $text;

 

Output:

<a href="http://www.somesite.com/help/index.php">Something</a> 
Blah Blah Blah
<a href="http://www.somesite.com/help/something.php">Something</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.