What do I call one function in another?

Asked

Viewed 48 times

0

I’m trying to call this function here

$bodyText = "The text you want to filter goes here.";

 function formatUrlsInText($text) {
 $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
 preg_match_all($reg_exUrl, $text, $matches);

 $usedPatterns = array(); 
 foreach($matches[0] as $pattern){
    if(!array_key_exists($pattern, $usedPatterns)){
       $usedPatterns[$pattern]=true;

       // now try to catch last thing in text 
       $pattern2 = substr($pattern, -3);

       if($pattern2 == "gif" || $pattern2 == "peg" || $pattern2 == "jpg" || $pattern2                    == "png") {
         $text = str_replace($pattern, '<img src="'.$pattern.'">', $text); 
       } else {
          $text = str_replace($pattern, '<a href="'.$pattern.'">'.$pattern.'</a>',      $text);
       } 
       }
       }
      return $text; 
     }

    $format = formatUrlsInText($bodyText);

    echo $format;

for that

<div class="video-page-desc">
<?php
if ($player_icons ['showTag'] == 1) {
  echo $this->htmlVideoDetails->description;
}
 ?>
</div>

The first function is to convert url in text for url clickable.
"note that at the end of the first function it is being converted to $bodyText = ""; that in the former case $bodyText = " "; only this in this function for testing."

The second function and where the description of the site comes out. "that I do not know much to say"

The goal and converts the url text of the description to url clickable

You could shed some light?

1 answer

1


To use this page function would simply make sure that the file containing it is included in the file you want to use it and do so:

<div class="video-page-desc">
<?php
  if ($player_icons ['showTag'] == 1) {
    echo formatUrlsInText($this->htmlVideoDetails->description);
  }
?>
</div>

But you need to make sure that the attribute $this->htmlVideoDetails->description returns a link, because it’s getting understood that description would be the description of the record, check if there is an attribute link, url or something like.

  • Vlw Rafael you’re the man

Browser other questions tagged

You are not signed in. Login or sign up in order to post.