I have string like this in database (the actual string contains 100s of word and 10s of variable): I echo this string like this: My output is I am a {$club} fan. I want I am a Barcelona fan. How can I do this? Answer Use strtr. It will translate parts of a string. For multiple values (demo): Program Output:
Tag: php
What is the best way to read last lines (i.e. “tail”) from a file using PHP?
In my PHP application I need to read multiple lines starting from the end of many files (mostly logs). Sometimes I need only the last one, sometimes I need tens or hundreds. Basically, I want something as flexible as the Unix tail command. There are questions here about how to get the single last line from a …
why select option value if zero post empty
I am sorry bad English. I have a select menu option value problem: I am if select value=”0″ option and this post, it retuns the value with no problem. But, when I use value = 0 save mysql table, this value not 0 this return empty. This value saving column type integer? What is problem? I am not us…
How to get closest date compared to an array of dates in PHP
This post almost answered this question for me, but I have a specific need and didn’t find what I sought there. This lies right outside my experience; couldn’t quite wrap my head around it, so all I really need is a point in the right direction. Let’s say I have an array as follows: I would …
Can you override interface methods with different, but “compatible”, signatures?
Consider the following PHP interfaces: I’m using PHPStorm, and when I do this, I get an error in the IDE that basically states the definition for add() in SuperCollection is not compatible with the definition in the interface it extends, Collection. In one way, I can see this being a problem, as the sig…
Custom mysqli prepare function
I’m doing my first own database class at the moment and currently I’m doing the prepare function. What this function does is to take in an SQL-query and then an array containing the variables for the …
rewrite url and let more parameters
I am rewriting this kind of urls http://deia.info/category/calendar/10/ To /index.php?task=browse_posts&catid=$2 By this code in the .htaccess RewriteRule ^category/(.+)/(.+) /index.php?task=…
php mysql export excel
This code is working without problem if page doesn’t contain any other content. When i add a html form, it gives only html content to excel. I need to use that form to customize query. How can i make this code working with html content? Answer As mentioned in the comments, combining HTML and CSV is not …
mysql sanitize row name
I’m currently writing a php framework with focus on security. I use a query builder to generate SQL-statements, so that it is not bound to MySQL. (Or SQL in general) I found certain posibilities that user could inject row names, so it has to escape them somehow. Because of how the query builder works, i…
Date and time in Greek
I’m currently using a website to get the time in Athens: $d = new DateTime(“now”, new DateTimeZone(“Europe/Athens”)); echo $d->format(“l, d M Y”); But I would like the date to be displayed in …