Skip to content

Tag: php

How can I replace a variable in a string with the value in PHP?

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:

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 …

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 …