fatbyjhnsn Posted January 29, 2007 Share Posted January 29, 2007 I just don't know PHP! I'm trying to learn, but its slow going.Here's the situation. I've got a wordpress plugin running, but I am having to fix some of the bugs myself. Basically, I'm trying to pull am image width from the wordpress outputted HTML code and insert it into the PHP code. Here's what I've got:There is a function get_between that is supposed to get some text between certain characters I specify:[code]function get_between ($input_text, $left_limit, $right_limit) { $ll = strpos($input_text, $left_limit) + strlen ($left_limit); $text1 = substr($input_text, $ll); $rl = strpos($text1, $right_limit); $text2 = substr($text1, 0, $rl); return $text2;}[/code]To get the characters I want (the width) from this image tag (I want 170 outputted):[code]<img src="http://www.xxx.com/wp-content/uploads/2007/01/593761.jpg" title="Man of the Year 1980" alt="Man of the Year 1980" align="right" height="250" width="170" />[/code]I use this call:[code]$image_src = get_between ($img_text, 'width="', '"');[/code]Then, this:[code]list ($img_width) = $image_src;[/code](I'm not sure why this is used above, it was in the code to begin with)Then finally this:[code]$div_open = '<div id="img_lgnd" style="position: relative; font-size: '.$current_settings['font_size'].'; border: '.$current_settings['border_size'].'px '.$current_settings['border_style'].' '.$current_settings['border_color'].'; margin: 1em; padding: 0em 0em 0em 0em; float: '.$image_align.'; max-width: '.$img_width.'px; max-height: 400px; height:auto !important;">';[/code](where $img_width) should be replaced by 170 in the outputted code.However, this doesn't work. The HTML output I get is:[code]<div id="img_lgnd" style="position: relative; font-size: ; border: px none ; margin: 1em; padding: 0em 0em 0em 0em; float: right; max-width: 1px; max-height: 400px; height:auto !important;">[/code]The width is 1px, obviously not right.Any ideas? I'm sure this is a really easy issue to take care of, I'm just so new at this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/ Share on other sites More sharing options...
HuggieBear Posted January 29, 2007 Share Posted January 29, 2007 OK, The list() is what's causing the problem. Comment that line out and in your $div_open variable, change $img_width to $img_src .RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172300 Share on other sites More sharing options...
fatbyjhnsn Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks for the reply!I thought that line was the problem as well, but its not the case. I comment it out, switch the variables, and the output HTML I get is:[code]<div id="img_lgnd" style="position: relative; font-size: ; border: px none ; margin: 1em; padding: 0em 0em 0em 0em; float: right; max-width: px; max-height: 400px; height:auto !important;">[/code]No 1, now it is just empty: max-width: px; Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172337 Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 ok can you confirm for me in that case, that the line that contains the code is actually in $img_text. As your code doesn't say that!You have this...[code=php:0]<img src="http://www.xxx.com/wp-content/uploads/2007/01/593761.jpg"....[/code] I'd expect it to say this...[code=php:0]$img_text = '<img src="http://www.xxx.com/wp-content/uploads/2007/01/593761.jpg"....';[/code] RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172341 Share on other sites More sharing options...
fatbyjhnsn Posted January 30, 2007 Author Share Posted January 30, 2007 I believe that's how it works. The text for getting the variable $img_text is:[code]while($img_start = strpos($data, $img_open) AND ($counter < (substr_count($data, $img_open)+1))) { //extract the string containing the whole img tag $img_text = substr($data, $img_start); $img_end = strpos($img_text, $img_close); $img_text = substr($img_text, 0, $img_end+1);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172347 Share on other sites More sharing options...
HuggieBear Posted January 30, 2007 Share Posted January 30, 2007 Functions upon functions upon functions...How long's the full code. If it's not too huge, maybe you could post it here?Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172353 Share on other sites More sharing options...
fatbyjhnsn Posted January 30, 2007 Author Share Posted January 30, 2007 Yeah, just my thought. Here it is from the beginning up to the <div> call in question. (that get_between) function appears right after:[code]// Some global variables$current_settings = get_option('gg_alttolgnd_options');$img_open = '<img';$img_close = '>';/** * This will search the text, look for the alt description within the * img HTML tag and duplicate it after the IMG tag * * @param $data string The content of the post. * @return string The new content with alttolgnds generated. */function gg_alttolgnd($data) { global $img_open, $img_close, $current_settings; $div_close = '</div>'; $img_incipit ='<img style="max-width: 300px; max-height: 280px; height:auto !important; "'; $text_style = '<p style="text-align:'.$current_settings['text_align'].'; font-style: italic; font-family: Arial, sans; font-size: 11px; color: #A4B7D0;" />'; $counter = 0; // Use Alt or Title? if ($current_settings['use_title'] == true) { $lgnd_open = 'title='; } else { $lgnd_open = 'alt='; } $lgnd_close = '"'; $lgnd_open_len = strlen($lgnd_open); $lgnd_close_len = strlen($lgnd_close);if (substr_count($data, $img_open)) { // Look for IMG tags, then for ALT within and create the legend while($img_start = strpos($data, $img_open) AND ($counter < (substr_count($data, $img_open)+1))) { //extract the string containing the whole img tag $img_text = substr($data, $img_start); $img_end = strpos($img_text, $img_close); $img_text = substr($img_text, 0, $img_end+1); // extract the src of the image and set the width of the box as big as the image width $image_src = get_between ($img_text, 'width="', '"'); // set floating left, right or according to the align parameter if ((substr_count($img_text, 'align=') > 0) AND ($current_settings['image_float'] == 'align')) { $image_align = get_between ($img_text, 'align="', '"'); } elseif ((substr_count($img_text, 'align=') == 0) AND ($current_settings['image_float'] == 'align')) { $image_align = 'left'; } else { $image_align = $current_settings['image_float']; } // this solves the URL file-access problem by taking away the sitename URI if image // is hosted locally $site_name = 'http://' . get_settings('siteurl') . '/'; if (substr_count($image_src, $site_name) > 0) { $image_src = str_replace ($site_name,'',$image_src); } // list ($img_width) = $image_src; // Set the apperarance of the borders and the image according to user settings if ( $current_settings['use_border'] == false ) { $current_settings['border_style'] = 'none' ;} $div_open = '<div id="img_lgnd" style="position: relative; font-size: '.$current_settings['font_size'].'; border: '.$current_settings['border_size'].'px '.$current_settings['border_style'].' '.$current_settings['border_color'].'; margin: 1em; padding: 0em 0em 0em 0em; float: '.$image_align.'; max-width: '.$img_src.'px; max-height: 400px; height:auto !important;">';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172356 Share on other sites More sharing options...
fatbyjhnsn Posted January 30, 2007 Author Share Posted January 30, 2007 bump!We're so close...hopefully someone can help me out! Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/36230-noob-here-this-has-got-to-be-easy-but/#findComment-172974 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.