Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:42:27+00:00 2026-05-26T19:42:27+00:00

My PHP class looks like that. <?php class htmlize { protected $base_dir; public function

  • 0

My PHP class looks like that.

 <?php
class htmlize {

    protected $base_dir;

    public function __construct( $base_dir = 'core/code/js/' )
    {
        $this->base_dir = $base_dir;
    }

    public function gimme_js_link ($list, $folder = '')
    {
        if(is_array($list)) {
        $links=array();
        foreach ($list as $name)
        {
            $links[]=$this->make_js_link ($name, $folder);
        }
        print_r ($links);
        }
        else {echo $this->make_js_link ($list, $folder);}
     }

     protected function make_js_link ($name, $folder)
     {
         $dir = $this->base_dir . $folder . '/';
         return '<script src="' . $dir . $name . '.js"></script>';
     }

  }

?>

Calling it like that

<? $js= new htmlize(); $js->gimme_js_link('jquery', 'libs'); ?>

The question is how can i get work this class either for array like 'jquery, ... , ...' or for single element for ex 'jquery'? Currently I made changes to gimme_js_link method: it checks $listvariable whether it’s array or not before processing.

But i feel that there must be more effective way, and we can shorten the code. Any suggestions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:42:27+00:00Added an answer on May 26, 2026 at 7:42 pm

    I took out the class properties so it can be run on codepad quickly.

    <?php
    function gimme_js_link( $list, $folder = '')
    {
        $list = explode( ',', $list);
        $links = array();
        foreach( $list as $name)
        {
            $links[] = make_js_link( trim( $name), $folder);
        }
        echo implode( '', $links);
    } 
    
    function make_js_link ($name, $folder)
    {
        $dir = $folder . '/';
        return '<script src="' . $dir . $name . '.js"></script>';
    }
    
    gimme_js_link( 'jquery, functions, files', 'libs');
    echo "\n";
    gimme_js_link( 'jquery', 'libs');
    

    Output:

    <script src="libs/jquery.js"></script><script src="libs/functions.js"></script><script src="libs/files.js"></script>
    <script src="libs/jquery.js"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that looks like this: utils/Result.php <?php class Result { public
I am reading some code that looks like that: Class_Menu.php: <?php class Menu {
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have an Entity class that looks like this: <?php namespace Entities; /** @Entity
I currently have my PHP class variables set up like this: class someThing {
MongoDB's excellent PHP driver allows me to write to write PHP code that looks
Is there a function, class, or extension in PHP that can handle the XSD
Is there a PHP class/library that would allow me to query an XHTML document
I have a PHP class that creates a PNG image on the fly and
I have certain PHP class methods that access external variables. These variables are not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.