Forum Moderators: coopster
<?
$regex = "/(WebForm_PostBackOptions\(.*\,.*\,.*\,.*\,[ ]*['\"]{1})([^'\"]*)/i";
$replaced = str_replace('"', '"', file_get_contents("myspace.txt"));
$replaced = preg_replace_callback($regex, "java_callback", $replaced);
function java_callback($matches)
{
return $matches[1].strtoupper($matches[2]);
}
echo $replaced;
?>
string to search in (the myspace.txt file):
BEFORE WebForm_PostBackOptions("ctl00$ctl00$Main$messagingMain$ReadMessage_Skin$AbuseButton", "", false, "", "http://collect.myspace.com/index.cfm?fuseaction=misc.contactInput&ProfileContentID=343035985&MyUserID=343035985&abuseflag=true", false, true) INBETWEEN WebForm_PostBackOptions("ctl00$ctl00$Main$messagingMain$ReadMessage_Skin$ReplyButton", "", false, "", "http://messaging.myspace.com/index.cfm?fuseaction=mail.reply&friendId=343035985&type=Inbox&messageID=154630601&fed=True", false, false) AFTER
result:
BEFORE WebForm_PostBackOptions("ctl00$ctl00$Main$messagingMain$ReadMessage_Skin$AbuseButton", "", false, "", "http://collect.myspace.com/index.cfm?fuseaction=misc.contactInput&ProfileContentID=343035985&MyUserID=343035985&abuseflag=true", false, true) INBETWEEN WebForm_PostBackOptions("ctl00$ctl00$Main$messagingMain$ReadMessage_Skin$ReplyButton", "", false, "", "HTTP://MESSAGING.MYSPACE.COM/INDEX.CFM?FUSEACTION=MAIL.REPLY&FRIENDID=343035985&TYPE=INBOX&MESSAGEID=154630601&FED=TRUE", false, false) AFTER
Both javascript functions match the regex, but only the 2nd one gets edited. If i switch them, still only the 2nd one gets edited. What it should do, is convert the url to uppercase in the first function as it does in the seccond. Save the long string into a file named myspace.txt and try it out. I've been looking into the regex and recoded it already but same problem happens, so i'm out of ideas.
Thanks in advance!
[edited by: Vis3R at 10:11 pm (utc) on Feb. 27, 2008]
[edited by: coopster at 7:41 pm (utc) on Mar. 3, 2008]
[edit reason] added "pre" tags to format code [/edit]
function java_callback($matches)
{
return $matches[1].strtoupper($matches[2]);
}
$replaced = str_replace('"', '"', $string);
$regex = "/(WebForm_PostBackOptions\([^,]+,[^,]+,[^,]+,[^,]+,\s*['\"])([^'\"]+)/i";
$replaced = preg_replace_callback($regex, "java_callback", $replaced);
print htmlentities($replaced);
I did not fetch the file from an external text file as you are but merely defined a string with the text you provided above. That is the only difference that could be causing you a problem because I tested the code that I posted and it worked fine. Therefore, I am deducing that perhaps your text file that you are fetching with file_get_contents may have newlines or something in it. If so, you may need to add an "s" modifier [php.net]. If you copy/paste the code that I used here do you still have the issue? If so, does your "myspace.txt" file contain just a simple string as you show above here? Newlines? Or no newlines?