eli311 Posted June 19, 2010 Share Posted June 19, 2010 Hi, So im trying to make a php function that turns [[img:testimage.png/Img]] to and url to the image. e.g. from: [[img:testimage.png/Img]] To: http://www.mytestsite.com/images/testimage.png Here is the string to change: Change this to an URL [[img:testimage.png/Img]] And this one [[img:testimage1.png/Img]] Here is the PHP Function: $string="Change this to an URL [[img:testimage.png/Img]] And this one [[img:testimage1.png/Img]]"; function findImage($string){ /* The Var's */ $Image_found = false; $ImageName = array(); $mystring = $string; $Image_Start = '[[img:'; $Image_End = '/Img]]'; /* The Var's */ /* Find if the Img tags are there */ $ImageCount1 = substr_count($mystring, $Image_Start); $ImageCount2 = substr_count($mystring, $Image_End); /* Find if the Img tags are there */ /* Find out where they are */ $WhereImage_Start = strpos($mystring, $Image_Start); $WhereImage_End = strpos($mystring, $Image_End); /* Find out where they are */ /* If the counts equal the same continue */ if($ImageCount1 == $ImageCount2){ if ($WhereImage_Start !== false && $WhereImage_End !== false) { $Image_found = true; } /* Start the loop */ if($ImageCount1 >= 1 && $Image_found == true){ for($i=0;$i<$ImageCount1;$i++){ $Find_image = substr($mystring, $WhereImage_Start+6, ($WhereImage_End-6)-$WhereImage_Start); $replace = IMG_LINK."/$Find_image"; $search = "$Image_Start$Find_image$Image_End"; $mystring = str_replace($search, $replace, $mystring); } /* End the loop */ /* Return new string */ echo $mystring."<br/></br>"; } }else{ /* Error Return start string*/ echo $mystring; } } findImage($string); This is what the function returns: Change this to an URL http://www.mytestsite.com/images/testimage.png And this one [[img:testimage1.png/Img]] Now this is not right it should have done both of them, but i can not get it to do more then one. Please can someone explain and help me to get it to do as many Img tags as there are. Thanks for any help Eli Stone Link to comment https://forums.phpfreaks.com/topic/205261-php-wiki-like-function/ Share on other sites More sharing options...
jskywalker Posted June 19, 2010 Share Posted June 19, 2010 in your while loop, you should re-assign "$WhereImage_Start" and "$WhereImage_End" to point to the second, (or third....) image.. Link to comment https://forums.phpfreaks.com/topic/205261-php-wiki-like-function/#findComment-1074394 Share on other sites More sharing options...
eli311 Posted June 19, 2010 Author Share Posted June 19, 2010 in your while loop, you should re-assign "$WhereImage_Start" and "$WhereImage_End" to point to the second, (or third....) image.. Well that was silly of me... i even pointed out thats where it finds them :-\ But thank you very much. Link to comment https://forums.phpfreaks.com/topic/205261-php-wiki-like-function/#findComment-1074398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.