FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Preg_Replace { tags }





cr3ativ3
I am not familiar with php's regular expressions however would like to learn it in the future. It seems alot more complicated then it needs to be....

But anyways I dont have the time right now to research it and would like to know if someone that is familiar with the expressions to right me a simple little preg_replace routin to replace anyting in a string {*} that follows that pattern where the * = wildcard.

Kind Regards,
Aaron
rvec
use (.*) instead of * Wink
"replaced by" is the text that should be in the $text string instead of {(.*)}


preg_replace( "{(.*)}", "replaced by", $text );
cr3ativ3
I appreciate that very much!

Kind Regards,
Aaron
cr3ativ3
$pageContents_unparsed = preg_replace('{(.*)}', '', $pageContents_unparsed);

This is what I have, but when I use that I lose the value of that variable totally, it totally just drops the value!

Just wondering what I am doing wrong.

Kind Regards,
Aaron
Star Wars Fanatic
cr3ativ3 wrote:
$pageContents_unparsed = preg_replace('{(.*)}', '', $pageContents_unparsed);

This is what I have, but when I use that I lose the value of that variable totally, it totally just drops the value!

Just wondering what I am doing wrong.

Kind Regards,
Aaron


Well it looks like you are replacing all instances of { (anything here) } with nothing, eg. ''. So if your variable is { text here, whatever... }. Then it replaces it with nothing.
cr3ativ3
Haha, your pretty funny! Ok misunderstanding, I am replacing any instances of {*} within a larger string. That does contain areas without that so I am confused why it is just dropping the entire contents............
Star Wars Fanatic
cr3ativ3 wrote:
Haha, your pretty funny! Ok misunderstanding, I am replacing any instances of {*} within a larger string. That does contain areas without that so I am confused why it is just dropping the entire contents............


My bad, I'm not sure what the problem is, it looks fine. Try outputting the variable to see exactly what the value is. Try var_dump.
imagefree
Try this!
Code:
$var='fedcba';
var_dump(preg_replace('/^.*$/', 'abcdef', $var));


it outputs

Code:
string(6) "abcdef"


is it what you want?
The code you pasted above just prints the second argument of preg_match twice.

hope it works. Very Happy
Related topics
Site Nav Suggestions...
Formatting Text - Different computer-output tags
Meta Tags
Meta-Tags
Why some script tags must put in the head of document?
login systeem
HTML: Automatically add ALT tags
Meta tags???
preg_replace with highlight_string
neep help making email form that accepts html tags
Robot.txt and Meta tags
htmlspecialchars
Decryption of text excrypted using md5() and crypt() tags
[Spoiler][/Spoiler] tags.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.