background preloader

Php

Facebook Twitter

jQuery and PHP inline editing. Inline editing as it’s known, or being able to edit content directly on a page is a great tool have under your belt. I’m going to run through exactly how it works as well as how to POST the updated text content through to a PHP script for server side processing to put in the database. The Code It looks a little complex so i’m going to quickly run through exactly what’s going on. When you visit the demo page are presented with a block of text. If you hover your mouse over the text you’ll see a little edit icon similar to when you want to edit content on FaceBook.If the user clicks on the block of code the text is replaced with a form textarea with the option to save or cancel any changes. Now in a little more detail This tutorial uses binding and unbinding. The PHP In this example I haven’t added the database connection script. The HTML The HTML is simply a list item with the class ‘inlineEdit’ this makes the content of the element editable.

PHP has a cool function that automatically highlights PHP code called highlight_string(); Theoretically this could be used to roll your own code highlighting on a site, rather than rely on JavaScript or some kind of external service to do it. In this article I'll show you the basics of how it works, then extended it with a few tricks. Since JavaScript is so similar to PHP in syntax, we can trick the function into highlighting JavaScript code as well. Then finally how we can bust out some smarts to auto-tab the code. Special thanks to Benjamin Mayo (Darren Beige) who wrote the format_javascript() function we'll check out below. Basic Usage The highlight_string() function just accepts a string, which must begin with <? <? The resulting HTML is: Which looks like this: Pretty wild eh? Trick it into highlighting JavaScript Benjamin Mayo (Darren Beige) put together a PHP function that would trick PHP into highlighting JavaScript code instead of exclusively PHP.

View Demo Download Files How it works. 9 Useful PHP Functions and Features You Need to Know. Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Nettuts+. Even after using PHP for years, we stumble upon functions and features that we did not know about. Some of these can be quite useful, yet underused. With that in mind, I've compiled a list of nine incredibly useful PHP functions and features that you should be familiar with. 1. Functions with Arbitrary Number of Arguments You may already know that PHP allows you to define functions with optional arguments. But there is also a method for allowing completely arbitrary number of function arguments. First, here is an example with just optional arguments: Now, let's see how we can build a function that accepts any number of arguments. 2. Many PHP functions have long and descriptive names.

Think of it like a more capable version of the scandir() function. You can fetch multiple file types like this: Note that the files can actually be returned with a path, depending on your query: 3. 4. 5. 6. 7. Criando funções que aceitem N argumentos. Hoje vou mostrar pra vocês como é facil criar uma função que aceite um número indeterminado de argumentos, é o mesmo caso das funções min() e max(), onde você pode passar 1, 2 ou 200 argumentos e ela irá funcionar perfeitamente. O ponto-chave desse tipo de função é o uso de duas outras funções nativas do PHP, são elas: func_num_args() e func_get_args(). A função func_num_args() (quando usada dentro de uma outra função) retorna o número de argumentos que foram passados para essa função. E a função func_get_args() retorna uma lista (array) com os argumentos que foram passados para essa função. Vamos criar uma função para calcular a média de uma quantiade qualquer de números: Perceba que, na definição da função, não colocamos nada no lugar dos parâmetros/argumentos que ela necessita… Exatamente por que a quantidade de argumentos será variável.

Agora vamos pegar o total e a lista de argumentos passados para a função: No final das contas, nossa função ficou assim: O uso dela é bem simples: PHP. Gerenciar é sempre o maior desafio quando falamos de empresas, é uma tarefa difícil, desgastante e que exige o máximo da nossa produtividade, mas não se preocupe, existem ferramentas desenvolvidas … Alguns programadores que iniciam com javascript acabam passando sempre por problemas de como entender Hoisting e Escopo, afinal WTF Man ???

Em mais uma promoção em parceria com a Novatec Editora, irei sortear aqui o livro Curso intensivo de Python. No mês passado na Caelum estava conversando com o time da Alura sobre quais features podiamos criar. No meio dessa conversa surgiram os seguintes questionamentos: “Mas o usuário não vai … Em mais uma promoção em parceria com a Novatec Editora, irei sortear aqui o livro [Expressões Regulares] Uma Abordagem Divertida.

Esse é meu primeiro review pra um livro da editora Casa do Código. Quando estamos editando o nosso portfólio em algum sistema web, temos um área para podermos arrastar uma nova foto que queremos, por exemplo, deixar de avatar.