esq.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for legal professionals and folks in law-adjacent fields. We abide by the Mastodon Server Covenant, available (here)[https://joinmastodon.org/covenant].

Administered by:

Server stats:

77
active users

#php

57 posts54 participants9 posts today

Hello everyone! 😀

TKZ Gastos ("TKZ Expenses" in English) offers a very simple way to convert an Excel (.xlsx) or OpenDocument (.odf) spreadsheet into a single, easy-to-read HTML page that displays expenses using JavaScript, HTML, and CSS. 🥰

This application makes it easy for donation-funded websites to publish their income and expenses transparently, so donors can see exactly where their contributions go, along with the current balance, historical data, and custom time periods. 💰💵

The project is available in several languages, and pull requests are welcome. I hope this small project proves useful to open-source initiatives that rely on donations and want to be transparent with their users and donors. Version 1.5 was released today. 🥳🎉

You may find the project at: 👇🏻
github.com/trankten/TKZgastos/

Demo available at:
tkz.es/gastos/

Any comments and feedback are always welcome and appreciated. :a2love:

Thanks you for reposting. 🔁

- Trankten :tkz:

Turns Excel or ODF into a filtrable webpage to show your project expenses for transparency purposes. - trankten/TKZgastos
GitHubGitHub - trankten/TKZgastos: Turns Excel or ODF into a filtrable webpage to show your project expenses for transparency purposes.Turns Excel or ODF into a filtrable webpage to show your project expenses for transparency purposes. - trankten/TKZgastos
#opensource#TKZ#GPL

How much time does it take for a new language to become standard in the corporate universe? I mean, I've been looking for a job for 4 months and I saw maybe one or two position involving #golang and I think I saw zero for #rust . In fact I I would say 95% is #python #c #c++ #csharp #java #javascript . There is a bit of #teraform and way too much #php in my tast. There is a bit of #ruby too. Ruby is ugly looking. Sorry. XD No #lua at all. I was surprised. Anyway. I just feel that the open source world is using way more interesting languages that the corporate world.

I have just released the biggest release in #loupe's history!

🚀 Major search engine overhaul!
🔧 Rewritten core logic
⚡ Faster queries & optimized SQLite
📊 Faceted search support!
🎯 Better ranking & aggregate sorting
📏 Offset, limit, total hit config
🧠 Smarter schema diffs & simpler queries
🖼️ Displayed attrs, cropping, highlights
📦 Configs & params now serializable
🔍 New Browse API
🛠️ Tons of fixes & polish!

Enjoy!

github.com/loupe-php/loupe/rel #php #search

🚀 New Loupe Release is Here — and It’s a Game Changer! 🔍✨
I am beyond excited to announce a MASSIVE update to Loupe! 😍
🔧 Rewritten search engine logic from the ground up
⚡ Even faster query handlin...
GitHubRelease 0.11.0 🔥 · loupe-php/loupe🚀 New Loupe Release is Here — and It’s a Game Changer! 🔍✨ I am beyond excited to announce a MASSIVE update to Loupe! 😍 🔧 Rewritten search engine logic from the ground up ⚡ Even faster query handlin...

Anyone here with knowledge of #PHP & the Mastodon-#API? Because I need help:

For my media table I collect the data for the media-accounts here via an PHP-script, that grabs the data from my accounts, that follow them.

But the script, which is heavily based( meaning "an amateurish rework") of a script by @to3k misteriously crahses, if the number of followers or (!!) of following can be divided by 8.

Anybody want to take a look and maybe help?
👉🏼 github.com/fingolas23/mastodon

Mastodon API scripts. Contribute to fingolas23/mastodon-api development by creating an account on GitHub.
GitHubGitHub - fingolas23/mastodon-api: Mastodon API scriptsMastodon API scripts. Contribute to fingolas23/mastodon-api development by creating an account on GitHub.

Stop using preg_* on HTML and start using \Dom\HTMLDocument instead

shkspr.mobi/blog/2025/05/stop-

It is a truth universally acknowledged that a programmer in possession of some HTML will eventually try to parse it with a regular expression.

This makes many people very angry and is widely regarded as a bad move.

In the bad old days, it was somewhat understandable for a PHP coder to run a quick-and-dirty preg_replace() on a scrap of code. They probably could control the input and there wasn't a great way to manipulate an HTML5 DOM.

Rejoice sinners! PHP 8.4 is here to save your wicked souls. There's a new HTML5 Parser which makes everything better and stops you having to write brittle regexen.

Here are a few tips - mostly notes to myself - but I hope you'll find useful.

Sanitise HTML

This is the most basic example. This loads HTML into a DOM, tries to fix all the mistakes it finds, and then spits out the result.

 PHP$html = '<p id="yes" id="no"><em>Hi</div><h2>Test</h3><img />';$dom = \Dom\HTMLDocument::createFromString( $html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED , "UTF-8" );echo $dom->saveHTML();

It uses LIBXML_HTML_NOIMPLIED because we don't want a full HTML document with a doctype, head, body, etc.

If you want Pretty Printing, you can use my library.

Get the plain text

OK, so you've got the DOM, how do you get the text of the body without any of the surrounding HTML

 PHP$html = '<p><em>Hello</em> World!</p>';$dom = \Dom\HTMLDocument::createFromString( $html, LIBXML_NOERROR , "UTF-8" );echo $dom->body->textContent;

Note, this doesn't replace images with their alt text.

Get a single element

You can use the same querySelector() function as you do in JavaScript!

 PHP$element = $dom->querySelector( "h2" );

That returns a pointer to the element. Which means you can run:

 PHP$element->setAttribute( "id", "interesting" );echo $dom->querySelector( "h2" )->attributes["id"]->value;

And you will see that the DOM has been manipulated!

Search for multiple elements

Suppose you have a bunch of headings and you want to get all of them. You can use the same querySelectorAll() function as you do in JavaScript!

To get all headings, in the order they appear:

 PHP$headings = $dom->querySelectorAll( "h1, h2, h3, h4, h5, h6" );foreach ( $headings as $heading ) {   // Do something}

Advanced Search

Suppose you have a bunch of links and you want to find only those which point to "example.com/test/". Again, you can use the same attribute selectors as you would elsewhere

 PHP$dom->querySelectorAll( "a[href^=https\:\/\/example\.com\/test\/]" );

Replacing content

Sadly, it isn't quite as simple as setting the innerHTML. Each search returns a node. That node may have children. Those children will also be node which, themselves, may have children, and so on.

Let's take a simple example:

 PHP$html = '<h2>Hello</h2>';$dom = \Dom\HTMLDocument::createFromString( $html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED, "UTF-8" );$element = $dom->querySelector( "h2" );$element->childNodes[0]->textContent = "Goodbye";echo $dom->saveHTML();

That changes "Hello" to "Goodbye".

But what if the element has child nodes?

 PHP$html = '<h2>Hello <em>friend</em></h2>';$dom = \Dom\HTMLDocument::createFromString( $html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED, "UTF-8" );$element = $dom->querySelector( "h2" );$element->childNodes[0]->textContent = "Goodbye";echo $dom->saveHTML();

That outputs <h2>Goodbye<em>friend</em></h2> - so think carefully about the structure of the DOM and what you want to replace.

Adding a new node

This one is tricky! Let's suppose you have this:

 HTML<div id="page">   <main>      <h2>Hello</h2>

You want to add an <h1> before the <h2>. Here's how to do this.

First, you need to construct the DOM:

 PHP$html = '<div id="page"><main><h2>Hello</h2>';$dom = \Dom\HTMLDocument::createFromString( $html, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED, "UTF-8" );

Next, you need to construct an entirely new DOM for your new node.

 PHP$newHTML = "<h1>Title</h1>";$newDom = \Dom\HTMLDocument::createFromString( $newHTML, LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED, "UTF-8" );

Next, extract the new element from the new DOM, and import it into the original DOM:

 PHP$element = $dom->importNode( $newDom->firstChild, true ); 

The element now needs to be inserted somewhere in the original DOM. In this case, get the h2, tell its parent node to insert the new node before the h2:

 PHP$h2 = $dom->querySelector( "h2" );$h2->parentNode->insertBefore( $element, $h2 );echo $dom->saveHTML();

Out pops:

 HTML<div id="page">   <main>      <h1>Title</h1>      <h2>Hello</h2>   </main></div>

An alternative is to use the appendChild() method. Note that it appends it to the end of the children. For example:

 PHP$div = $dom->querySelector( "#page" );$div->appendChild( $element );echo $dom->saveHTML();

Produces:

 HTML<div id="page">   <main>      <h2>Hello</h2>   </main>   <h1>Title</h1></div>

And more?

I've only scratched the surface of what the new 8.4 HTML Parser can do. I've already rewritten lots of my yucky old preg_ code to something which (hopefully) is less likely to break in catastrophic ways.

If you have any other tips, please leave a comment.

The PHP logo.
Terence Eden’s Blog · Stop using preg_* on HTML and start using \Dom\HTMLDocument instead
More from Terence Eden

So my 11 year old is doing coding. Primarily at the moment PHP.

He's currently using VS Code, but I would love him to use PhpStorm, as it's so much better for PHP. But obviously he doesn’t have the money to pay for it.

I know PhpStorm has free licenses for University and High School students, but there are still a good few years to go.

Does anyone know if Jetbrains has a way for primary school kids to access free PhpStorm licenses?

Replied in thread

@chriscoyier

$ cd ~/Dev/wp-theme-ttnet
$ subl style.css
$ git add -p && git commit && git push prod

... where "prod" is an SSH remote on my Apache server.

Basically, a modern take on classic FTP but with (private) version control.

Usually between step 2 and 3, I'll select all and copy-paste to replace the stylesheet in devtools to preview the changes. For more complex changes I nigh use local WP or write them within the browser and copy back.

github.com/Krinkle/timotijhof.

Contribute to Krinkle/timotijhof.net development by creating an account on GitHub.
GitHubGitHub - Krinkle/timotijhof.netContribute to Krinkle/timotijhof.net development by creating an account on GitHub.

Vorresti sviluppare un #Agente #LLM da integrare nella tua applicazione per sfruttare l’ondata di popolarità data dall’#AI in quest’ultimo periodo, ma purtroppo il tuo software è un monolita #PHP e in giro senti parlare solamente di #Python? ;-)

Niente paura, #NeuronAI è il framework che fa per te! ;)

youtu.be/zHNZNtGjqKE

youtu.be- YouTubeEnjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.

It seems to me that the #Python ecosystem hasn’t embraced design patterns to the degree that #PHP has. No judgment, I’m somewhere in the middle of that spectrum myself. Just an observation as I have feet in both worlds.