cowboysdude Posted February 1, 2011 Share Posted February 1, 2011 I am trying to make it so the user can change the thumbnail size of a picture.... this is what I've got because I had to do a str_replace to first add the width and height into the html on output.... NOW I'm trying to have the ability to resize them... here is what I currently have... $videos[$i]['img'] = str_replace(">"," width=40% height=40% >", $matches[0]); I have tried: $videos[$i]['img'] = str_replace(">"," width=$xy height=$xy >", $matches[0]); changing size by %... but it returns nothing in the html. Then I tried to do a total substitute and do this... <?php $xy = $params->get('xy'); $xypic = " width=$xy height=$xy >"; $videos[$i]['img'] = str_replace(">", $xypic , $matches[0]); That doesn't work either it returns nothing in the html... Is there a way to make this work? I've tried a few different ways but no luck.... Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted February 1, 2011 Share Posted February 1, 2011 What is the contents of $matches[0] ? And what is the contents of $videos[$i]['img'] after doing the substitution? Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted February 1, 2011 Author Share Posted February 1, 2011 $rss = new SimpleXMLElement($data); $i = 0; $videos = array(); foreach($rss->channel->item as $item){ $videos[$i]['title'] = (string) $item->title; $videos[$i]['link'] = (string) $item->link; $description = (string) $item->description; $matches = array(); preg_match("/<img[^<>]+>/",$description,$matches); $videos[$i]['img'] = str_replace(">"," width=40% height=40% >", $matches[0]); $i++; if($i>=$totalvid) break; } return $videos; } } Quote Link to comment Share on other sites More sharing options...
btherl Posted February 1, 2011 Share Posted February 1, 2011 Please add some code around this line: $videos[$i]['img'] = str_replace(">"," width=40% height=40% >", $matches[0]); So it looks like this: print "Original string: {$matches[0]}<br>"; $videos[$i]['img'] = str_replace(">"," width=40% height=40% >", $matches[0]); print "Replacement: {$videos[$i]['img']}<br>"; then run the script and copy and paste the output Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted February 5, 2011 Author Share Posted February 5, 2011 This is the output: Original string: Replacement: That's pretty much it... Quote Link to comment Share on other sites More sharing options...
btherl Posted February 6, 2011 Share Posted February 6, 2011 The problem is that $matches[0] is empty. Try printing out each $description value that you process, and see if they match the expression you are using in preg_match() Quote Link to comment Share on other sites More sharing options...
cowboysdude Posted February 6, 2011 Author Share Posted February 6, 2011 OK sounds good. It's just odd because it shows the video thumbnail fine and plays the video so not sure why that's coming back empty... interesting... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.