• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

preg_replace question

Joined
Jun 26, 2006
Messages
37
this may sound kinda n00bish but i cannot figure out why my preg_replace function is not working. I'll be honest and i'm not up to par with all the different string formatting options, so i think thats the problem i'm having.

i've gotten tested everything and ti works up to this point. the problem is in my preg_replace but i cant find it, anyone see anything wrong with this?

PHP:
$pattern = '/\[youtube\](.*?)\[\/youtube\]/is,';
$replacement = '<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/'.$stringVid.'"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/'.$stringVid.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
</object>';

$str2 = preg_replace($pattern, $replacement, $str2, 1); // replace each individual occurance

I've added a youtube insert function in my site, this parses the bbc code and replaces it with the youtube video code
 
Maybe you can explain what you really want to do? Expected inputs, outputs & whatnot...
 
the input is a thread exactly like this for example.

The code is part of my forum that translates bulliten board code into html, such as..

PHP:
[b][/b] = <i></i>
[url=http://whatever.com]whatever[/whatever] = <a href=http://whatever.com>whatever</a>

this is the same thing, i't calls the function to parse the youTube bbc which is indicated by
PHP:
[youtube]siteaddress[/youtube]

they way it works is i do a preg_match_all and could the number of times i find it. then i run a loop for each one and run a replace statement.

once i finish the loop, i return the newley edited string which is the thread. all the youtube bbc's should be translated into the html to show a youtube video.

what i provided in my first thread was the code to go inside the loop, this is where i do the actual translating of the bbc into html. I tested everything. the replacement thread right before the preg_replace function is called shows the html exactly as i want it to, so that meens that there is an error in my preg_replace function. Only problem is, i'm not sure exactly what it is?

the pattern is correct, the replacement seems to be correct, the str2 is correct, and the limi is correct as well (that limits one change at a time, if i didn't do that and someone inserted multiple youtube vids, they'd all be written as the same youtube vid)

so if anyone can help me, i would really appreciate it.
 
first,
Code:
$pattern = '/\[youtube\](.*?)\[\/youtube\]/is[u],[/u]';
not sure why that comma is there, it shouldnt be.
also, there is no $1 placeholder in your replacement string

are you actually getting an error message? that would be helpful
 
yeah taking out the comma fixed everything, i actually just now found that and was about to let everyone know just exactly how important detailed proof reading is, lol maybe 15 minutes of coding and a couple hours of debugging.

and also i didn't pu tthe place holder in there because of the nature of the link.

a youtube link is like this, "http://www.youtube.com/watch?v=Yx9FgLr9oTk"
while in the param is like this, "http://www.youtube.com/v/Yx9FgLr9oTk"

So i take that id in the link after the "=" with an explode(); and set that ID = to $stringVid, and reinsert that. using a place holder wouldn't have worked the way i did the search. I probably could have come up with a better pattern but those things kill me sometimes and i wasn't sure how to make it look for the first part of the url and the second, so i just lumped it all together in this case.

but it works now :D

EDIT: and it was weird because looking at the php.net definition it should have returned the $str2 unchanged since it wasn't finding the pattern, but instead it made it blank every time? i'm guessing the comma just made it do some weird things. - no error messages, just a blank values for $str2
 
Back
Top