Jump to content

Recommended Posts

Hi guys

 

I was wondering if anyone could point me in the right direction with this.

 

I am using JSON to return the contents of a directory and then using a foreach loop to print each one to a new row in a table.

 

Is there anyway to filter the results? Basically I just want to show the files that end in a .jar extension? Currently all sub directories and files are shown, however all the files I need to pull will be in the main directory.

 

This is what I am using:

 

<?php
				foreach ($installedplugins1['success'] as $v) 
			{
				echo "<tr><td>".$v."</td>";
				echo "<td><a href='index.php?dp=".$v."'>Disable Plugin</a></td>";

			}
		?>

 

Any hints or reading material?

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/260472-filtering-arrays-help/
Share on other sites

you can filter an array using the oddly named function array_filter().

 

heh...

Psycho, my thoughts are that the OP stated he is grabbing files from a directory and looping through them to display them each in a new tbl row.

I'm thinking he can use glob to grab all of the .jar files from the directory and foreach through them that way, something like this:

 

?>
<table>
<?php
foreach(glob("/path/to/dir/*.jar") as $filename)
{
    echo "<tr><td>".$filename."</td>";
    echo "<td><a href='index.php?dp=".$filename."'>Disable Plugin</a></td></tr>";
}
?>
</table>

 

then again, I can only guess on the actual logic at this point.

you can filter an array using the oddly named function array_filter().

 

heh...

Psycho, my thoughts are that the OP stated he is grabbing files from a directory and looping through them to display them each in a new tbl row.

I'm thinking he can use glob to grab all of the .jar files from the directory and foreach through them that way, something like this:

 

 

Unless one of the files happens to be named .JAR, .Jar, etc. Then, using "*.jar" in the glob() function will not work. glob() doesn't accept true regex expressions, but you can build a case-insensitive expression using the function I posted above.

you can filter an array using the oddly named function array_filter().

 

heh...

Psycho, my thoughts are that the OP stated he is grabbing files from a directory and looping through them to display them each in a new tbl row.

I'm thinking he can use glob to grab all of the .jar files from the directory and foreach through them that way, something like this:

 

 

Unless one of the files happens to be named .JAR, .Jar, etc. Then, using "*.jar" in the glob() function will not work. glob() doesn't accept true regex expressions, but you can build a case-insensitive expression using the function I posted above.

 

ah, just noticed the edit to your thread, yes that should work, any clue what the non-deprecated function is now, if one exists?.

But again, until the OP responds, we can really only guess at the actual logic and if this will work in this case.

Hi Guys

 

Thanks for all your responses, the data is coming from an API into the minecraft extension bukkit, my actual results from query display as:

 

"result": "success",
    "source": "getDirectory",
    "success": ["plugins/Essentials.jar", "plugins/Essentials/", "plugins/Essentials/config.yml", "plugins/Essentials/items.csv", "plugins/Essentials/upgrades-done.yml", "plugins/Essentials/warps/", "plugins/Essentials/worth.yml", "plugins/JSONAPI.jar", "plugins/JSONAPI/", "plugins/JSONAPI/config.yml", "plugins/JSONAPI/config_rtk.yml", "plugins/JSONAPI/methods.json", "plugins/JSONAPI/methods/", "plugins/JSONAPI/methods/permissions.json", "plugins/JSONAPI/methods/readme.txt", "plugins/JSONAPI/methods/remotetoolkit.json", "plugins/JSONAPI/methods/system.json", "plugins/JSONAPI/methods/world.json", "plugins/MinecraftRKitPlugin.jar", "plugins/PluginMetrics/", "plugins/PluginMetrics/config.yml"]
}

 

So all I am trying to do is extract the results that end in .jar and ignore the rest so I can have a list of installed plugins.

 

 

FYI: Here is a case-insensitive glob() solution to find ".jar" files

$files = glob("/path/to/dir/*.".sql_regcase('jar'));

 

BUt, to the OP's problem, since the data is created externally the array_filter() function is probably the correct solution.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.