Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
For Each ... in String
Old 01-17-2010, 04:08 PM For Each ... in String
Junior Talker

Posts: 2
Name: Daniel
Trades: 0
Okay I'm making a blog-type-thing and I have a script to replace
Code:
[video title="thing"][/video]
with and embed code and it works great but the problem is when there are multiple occurrences of it then it doesn't work. Heres the script I have to do the replacing:

Code:
$article = $row['post'];
$matches = array();
preg_match('/\[video title="([^"]*)"\]\[\/video\]/', $article, $matches);
if(!empty($matches)) {
	$vtitle = $matches[1];
	$vtitleclean = str_replace(" ", "_", $vtitle);

	$vfultitle = $vtitleclean . md5($vtitleclean) . ".flv";

	$old = "[video title=\"" . $vtitle . "\"][/video]";
	$new = "<object classid=\"clsid:F08DF954-8592-11D1-B16A-00C0F0283628\" id=\"PlayerObj\" width=\"400\" height=\"468\">
			<param name=\"quality\" value=\"high\">
			<param name=\"bgcolor\" value=\"#000000\">
			<param name=\"flashvars\" value=\"sv=" . $vfultitle . "&skin=incs/video player/SkinOverPlaySeekMute.swf&width=468&height=400\">
			<param name=\"width\" value=\"468\">
			<param name=\"height\" value=\"400\">
			<param name=\"scale\" value=\"noscale\">
			<param name=\"salign\" value=\"tl\">
			<param name=\"name\" value=\"Player\">
			<param name=\"type\" value=\"application/x-shockwave-flash\">
			<param name=\"pluginspage\" value=\"http://www.adobe.com/go/getflashplayer\">
			<embed src=\"incs/video/player.swf\" quality=\"high\" bgcolor=\"#000000\" flashvars=\"sv=videos/" . $vfultitle . "&skin=incs/video/SkinOverPlaySeekMute.swf&width=468&height=400\" width=\"468\" height=\"400\" scale=\"noscale\" salign=\"tl\" name=\"Player\" type=\"application/x-shockwave-flash\"pluginspage=\"http://www.adobe.com/go/getflashplayer\"> </embed>
		</object>";
	$blog_post = str_replace($old, $new, $blog_post);
}
but when there there are more than one things to replace only the first one works. I'm assuming I'd use the "foreach() function but I don't know what to do. If anyone could help me out then that would be great.

Thanks,
Daniel
danielair is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-17-2010, 04:46 PM Re: For Each ... in String
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Basically, instead of
PHP Code:
if (!empty($matches)) {
   
// ...

use
PHP Code:
foreach ($matches as $match) {
   
// ...

__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 01-17-2010, 08:18 PM Re: For Each ... in String
Junior Talker

Posts: 2
Name: Daniel
Trades: 0
When I tried this it didnt show anything when it should have been displaying two movies...

Daniel
danielair is offline
Reply With Quote
View Public Profile
 
Old 01-18-2010, 01:42 AM Re: For Each ... in String
Extreme Talker

Posts: 206
Name: vikas
Trades: 0
It should work .. can you check whether the video is at the place and working properly as standalone
__________________

Please login or register to view this content. Registration is FREE
Collection of free online books and free ebooks
Please login or register to view this content. Registration is FREE
- Free online pdf books and free pdf eBooks
vikas1234 is offline
Reply With Quote
View Public Profile
 
Old 01-18-2010, 01:43 AM Re: For Each ... in String
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Did you also change $vtitle? It should now be
PHP Code:
$vtitle $match
Edit: Oh, and if the first match ($matches[0]) should be skiped, you're better of using this:
PHP Code:
for ($i 1$i count($matches); $i++) {
   
$vtitle $matches[$i];
   
// ...

__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 01-18-2010 at 01:46 AM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to For Each ... in String
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20359 seconds with 12 queries