# General PHP Help

**URL:** https://www.phphelp.com/c/general-php-help/5.md

[Latest](https://www.phphelp.com/latest.md) · [Categories](https://www.phphelp.com/categories.md)

---

## [About the General PHP Help category](https://www.phphelp.com/t/about-the-general-php-help-category/8535)

<div class="topic-metadata">

**Author:** [@system](https://www.phphelp.com/u/system)\
**Replies:** 2\
**Last updated:** [October 30, 2023, 4:10pm UTC](https://www.phphelp.com/t/about-the-general-php-help-category/8535 "2023-10-30T16:10:54Z")

</div>

General questions about PHP programming. If you’re having problem with your PHP code and need help - post your question and/or code here. If you want to request a specific script or code snippet - post it to the Code Sni…

---

## [Mb\_str\_pad and escape sequences](https://www.phphelp.com/t/mb-str-pad-and-escape-sequences/36703)

<div class="topic-metadata">

**Author:** [@mcg](https://www.phphelp.com/u/mcg)\
**Replies:** 2\
**Last updated:** [July 28, 2026, 6:07pm UTC](https://www.phphelp.com/t/mb-str-pad-and-escape-sequences/36703 "2026-07-28T18:07:30Z")

</div>

Hello all; When padding a string for display in a CLI script, I’ve found that escape sequences seem to confuse the mb\_str\_pad() function. Specifically, say I want a list of results for the word time: pretend the result…

---

## [Merging One Array's Key on Second Array's Values](https://www.phphelp.com/t/merging-one-arrays-key-on-second-arrays-values/36682)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 17\
**Last updated:** [December 29, 2025, 3:40am UTC](https://www.phphelp.com/t/merging-one-arrays-key-on-second-arrays-values/36682 "2025-12-29T03:40:36Z")

</div>

I have two two-dimensional arrays that need to be merged into a single multi-dimensional array that has all values based on matching the key in one to one of the values in the other. The example below has been simplified…

---

## [Problem with while loop](https://www.phphelp.com/t/problem-with-while-loop/36681)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 3\
**Last updated:** [December 27, 2025, 9:07pm UTC](https://www.phphelp.com/t/problem-with-while-loop/36681 "2025-12-27T21:07:55Z")

</div>

I have a little panel on the site’s home page which should show news items recently submitted. If there are no news items, the panel is not shown. There is a form which sends an item to a DB table. This works, I have che…

---

## [Date() or strtotime() Losing Day Value](https://www.phphelp.com/t/date-or-strtotime-losing-day-value/36680)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 3\
**Last updated:** [December 20, 2025, 12:23am UTC](https://www.phphelp.com/t/date-or-strtotime-losing-day-value/36680 "2025-12-20T00:23:18Z")

</div>

In a MySQL DATE column with the date formatted as 1954-06-15, date('Y-m-d', strtotime($row)) returns 1954-06-01 every time. Am I missing something here?

---

## [Php mail not received by gmail](https://www.phphelp.com/t/php-mail-not-received-by-gmail/36659)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 12\
**Last updated:** [December 15, 2025, 4:14pm UTC](https://www.phphelp.com/t/php-mail-not-received-by-gmail/36659 "2025-12-15T16:14:09Z")

</div>

First off, this isnt a coding problem but a general question. I have written a PHP routine that sends email from a form. It works, because I got the test mail message straight away, and correctly formatted, on my non-gma…

---

## [DIRECTORY\_SEPARATOR vs Hard-Coded Slash](https://www.phphelp.com/t/directory-separator-vs-hard-coded-slash/36588)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 8\
**Last updated:** [December 7, 2025, 10:44pm UTC](https://www.phphelp.com/t/directory-separator-vs-hard-coded-slash/36588 "2025-12-07T22:44:05Z")

</div>

This is more of a comment than it is a question. Typically my development sites run on a desktop PC under Linux and Apache so I’ve always just hard-coded slashes but I’m in the midst of completely reprogramming everythi…

---

## [Reading a text file from remote server into function, div and span](https://www.phphelp.com/t/reading-a-text-file-from-remote-server-into-function-div-and-span/36667)

<div class="topic-metadata">

**Author:** [@mpg](https://www.phphelp.com/u/mpg)\
**Replies:** 2\
**Last updated:** [December 6, 2025, 8:46pm UTC](https://www.phphelp.com/t/reading-a-text-file-from-remote-server-into-function-div-and-span/36667 "2025-12-06T20:46:27Z")

</div>

I can successfully read this file as expected using echo… \<?php echo file\_get\_contents("http://pictureclock.ca/ip/ip.txt"); ?\> But I can’t seem to read this the same way in this code, i must be missing something. Perha…

---

## [Contenate User Global in Inline Style](https://www.phphelp.com/t/contenate-user-global-in-inline-style/36660)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 4\
**Last updated:** [November 25, 2025, 11:09pm UTC](https://www.phphelp.com/t/contenate-user-global-in-inline-style/36660 "2025-11-25T23:09:16Z")

</div>

I can’t seem to work out the syntax for adding a user defined global variable value into an inline style that uses single quotes. This is the line as it is and working: $Output .= "\<img id=\\"".COMMON\_REL\_IMAGES."refres…

---

## [One block works but not the other](https://www.phphelp.com/t/one-block-works-but-not-the-other/36654)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 6\
**Last updated:** [November 23, 2025, 11:31pm UTC](https://www.phphelp.com/t/one-block-works-but-not-the-other/36654 "2025-11-23T23:31:46Z")

</div>

Thought it was too good to last! Smitten with my own success(?) I have also done a form which allows the sending of the same email to either all members or just the committee members. Form contains 2 radio buttons, same …

---

## [Image not showing although other variables are](https://www.phphelp.com/t/image-not-showing-although-other-variables-are/36652)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 2\
**Last updated:** [November 20, 2025, 9:56am UTC](https://www.phphelp.com/t/image-not-showing-although-other-variables-are/36652 "2025-11-20T09:56:10Z")

</div>

I have a page that gets 4 bits of info from a small database. I know it works because all of the other variables are echoed properly. The one that doesnt get echoed is the variable for the picture. I get the ‘broken imag…

---

## [Can I use a PHP variable in a session?](https://www.phphelp.com/t/can-i-use-a-php-variable-in-a-session/36615)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 17\
**Last updated:** [November 14, 2025, 4:30pm UTC](https://www.phphelp.com/t/can-i-use-a-php-variable-in-a-session/36615 "2025-11-14T16:30:19Z")

</div>

I have a routine which gets member info from a database (works fine!) and puts the data into text boxes on a form (also works fine). The form has 2 buttons, one to update the details in the text boxes, the other to delet…

---

## [Adding Color Gradient to Text in ImageMagick](https://www.phphelp.com/t/adding-color-gradient-to-text-in-imagemagick/36645)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 2\
**Last updated:** [November 13, 2025, 3:21am UTC](https://www.phphelp.com/t/adding-color-gradient-to-text-in-imagemagick/36645 "2025-11-13T03:21:22Z")

</div>

Just starting with ImageMagick after having used GD Library for decades and so far ImageMagick is far, far easier! However, I can’t seem to create a horizontal gradient in the first block in the code below. I would like …

---

## [Insert html code into a mysql/mariadb field](https://www.phphelp.com/t/insert-html-code-into-a-mysql-mariadb-field/36649)

<div class="topic-metadata">

**Author:** [@icebowl](https://www.phphelp.com/u/icebowl)\
**Replies:** 3\
**Last updated:** [November 10, 2025, 2:17pm UTC](https://www.phphelp.com/t/insert-html-code-into-a-mysql-mariadb-field/36649 "2025-11-10T14:17:23Z")

</div>

I want to be able to insert html code into a mysql/mariadb field. Security is not an issue. It is a local network. number is longtext Here is my table: CREATE TABLE \`formdata\` ( \`id\` int(32) NOT NULL AUTO\_INCREMEN…

---

## [Php mail script being activated by bots](https://www.phphelp.com/t/php-mail-script-being-activated-by-bots/36364)

<div class="topic-metadata">

**Author:** [@increase](https://www.phphelp.com/u/increase)\
**Replies:** 7\
**Last updated:** [November 1, 2025, 7:12pm UTC](https://www.phphelp.com/t/php-mail-script-being-activated-by-bots/36364 "2025-11-01T19:12:48Z")

</div>

I have two php scripts which send out mail to a group and are executed by site admin from a password ptotecetd menu, but the scripts keeps getting activated by bots scarping the site. I have tried to set a robots.txt fi…

---

## [File Size problem](https://www.phphelp.com/t/file-size-problem/36642)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 2\
**Last updated:** [October 29, 2025, 11:35pm UTC](https://www.phphelp.com/t/file-size-problem/36642 "2025-10-29T23:35:50Z")

</div>

Hi, I have hit a bit of a hiccup! Doing some testing before completing a file upload, and my problem is the opposite to most file size troubles! I want to put a limit on the size a user can upload, and to do this I have…

---

## [Logic right but variable do not stay on error, status line?](https://www.phphelp.com/t/logic-right-but-variable-do-not-stay-on-error-status-line/36628)

<div class="topic-metadata">

**Author:** [@cdlvj130](https://www.phphelp.com/u/cdlvj130)\
**Replies:** 6\
**Last updated:** [October 20, 2025, 2:18am UTC](https://www.phphelp.com/t/logic-right-but-variable-do-not-stay-on-error-status-line/36628 "2025-10-20T02:18:49Z")

</div>

\<?php //Logic php is re-entrant. User enters data, db good, fields reset and message on status line. //can enter again, have to add button to return to main menu. //if db error, display error on status line, leave data i…

---

## [Variable is out of scope](https://www.phphelp.com/t/variable-is-out-of-scope/36626)

<div class="topic-metadata">

**Author:** [@cdlvj130](https://www.phphelp.com/u/cdlvj130)\
**Replies:** 1\
**Last updated:** [October 19, 2025, 3:43pm UTC](https://www.phphelp.com/t/variable-is-out-of-scope/36626 "2025-10-19T15:43:22Z")

</div>

why is my code all catawampus? dbopen return the PDO object which passed to dbupdate and is undefined at that point, WHY? include(“db.php”); include(“config.php”); $pdo=""; if ($\_SESSION\[“onlinestat”\] == “0”) { …

---

## [Best implementation forms entry](https://www.phphelp.com/t/best-implementation-forms-entry/36622)

<div class="topic-metadata">

**Author:** [@cdlvj130](https://www.phphelp.com/u/cdlvj130)\
**Replies:** 12\
**Last updated:** [October 17, 2025, 6:53pm UTC](https://www.phphelp.com/t/best-implementation-forms-entry/36622 "2025-10-17T18:53:40Z")

</div>

I have a forms.php to get contact data, name, address, etc. Last field is a status line of 72 bytes. with submit, reset & cancel buttons. action=update.php method=POST update.php inserts the data into mysql table, and…

---

## [Sql query with date not going to database](https://www.phphelp.com/t/sql-query-with-date-not-going-to-database/36587)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 11\
**Last updated:** [October 16, 2025, 2:44am UTC](https://www.phphelp.com/t/sql-query-with-date-not-going-to-database/36587 "2025-10-16T02:44:21Z")

</div>

Hi, I am having huge trouble getting a date to the DB. Values for month,day,year come from text boxes on a form. I get no ‘die’ message but the database is empty. I am sure my confusion arises due to the difference betwe…

---

## [Try and catch not working - duplicate key](https://www.phphelp.com/t/try-and-catch-not-working-duplicate-key/36618)

<div class="topic-metadata">

**Author:** [@cdlvj130](https://www.phphelp.com/u/cdlvj130)\
**Replies:** 9\
**Last updated:** [October 15, 2025, 5:15pm UTC](https://www.phphelp.com/t/try-and-catch-not-working-duplicate-key/36618 "2025-10-15T17:15:59Z")

</div>

\<?php include("config.php"); extract($\_POST); $sql = "INSERT INTO contacts (firstname, lastname, phone, email, address, city, state, zipcode) VALUES ('$fname','$lname','$phone','$email','$address','$city','$state','$z…

---

## [Determing if Datetime or Timestamp](https://www.phphelp.com/t/determing-if-datetime-or-timestamp/36606)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 3\
**Last updated:** [October 7, 2025, 11:46pm UTC](https://www.phphelp.com/t/determing-if-datetime-or-timestamp/36606 "2025-10-07T23:46:51Z")

</div>

I’m slowly converting all my sites over from the Unix Timestamp to MySQL Datetime and in the process I need a way to determine which it is so that the sites do not break or crash while working on them. For the most part …

---

## [Form not passing data between directories](https://www.phphelp.com/t/form-not-passing-data-between-directories/36593)

<div class="topic-metadata">

**Author:** [@mackenzie27](https://www.phphelp.com/u/mackenzie27)\
**Replies:** 1\
**Last updated:** [September 30, 2025, 3:52pm UTC](https://www.phphelp.com/t/form-not-passing-data-between-directories/36593 "2025-09-30T15:52:27Z")

</div>

I have a simple form that is not passing any data when I click the submit button. Here is the code for the form. \<form method="post" action="https://www.domain.com/play/\<?php echo $playDirectory ?\>/links"\> \<input t…

---

## [How do i insert a mailto link around a php variable?](https://www.phphelp.com/t/how-do-i-insert-a-mailto-link-around-a-php-variable/36582)

<div class="topic-metadata">

**Author:** [@babystarman](https://www.phphelp.com/u/babystarman)\
**Replies:** 7\
**Last updated:** [September 26, 2025, 2:22pm UTC](https://www.phphelp.com/t/how-do-i-insert-a-mailto-link-around-a-php-variable/36582 "2025-09-26T14:22:05Z")

</div>

I have a routine that shows records from a database. It works perfectly well, but one of the fields is a (plain text) email address saved in a PHP $row variable. How do I make that variable a ‘mailto’ link so that it bec…

---

## [Never done class() in php](https://www.phphelp.com/t/never-done-class-in-php/36579)

<div class="topic-metadata">

**Author:** [@Paul-D](https://www.phphelp.com/u/Paul-D)\
**Replies:** 1\
**Last updated:** [September 24, 2025, 4:21pm UTC](https://www.phphelp.com/t/never-done-class-in-php/36579 "2025-09-24T16:21:06Z")

</div>

I have done lots of class in C++ which is a very long time ago. I have never attempted this in php. Here is what I was looking at. Please not too crital over this but I am interested in pulic and private variables and fu…

---

## [Global Variable Not working](https://www.phphelp.com/t/global-variable-not-working/36576)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 4\
**Last updated:** [September 23, 2025, 11:23pm UTC](https://www.phphelp.com/t/global-variable-not-working/36576 "2025-09-23T23:23:04Z")

</div>

NOTE: I deleted this post just moment after posting when I finally spotted the errors so not sure how you replied. What would cause a $\_POST to give such an error? I thought it was a global that was built into PHP. PH…

---

## [Simple PHP code functions failing for no apparent reason](https://www.phphelp.com/t/simple-php-code-functions-failing-for-no-apparent-reason/36524)

<div class="topic-metadata">

**Author:** [@mackenzie27](https://www.phphelp.com/u/mackenzie27)\
**Replies:** 4\
**Last updated:** [August 4, 2025, 6:49pm UTC](https://www.phphelp.com/t/simple-php-code-functions-failing-for-no-apparent-reason/36524 "2025-08-04T18:49:50Z")

</div>

Please ignore the following. It was a false alarm based on a type. I have recently gone from using php version 5-something to php version 8-something (thanks to a change in hosting platforms), and I am running into som…

---

## [RecursiveDirectoryIterator and RecursiveIteratorIterator](https://www.phphelp.com/t/recursivedirectoryiterator-and-recursiveiteratoriterator/36507)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 1\
**Last updated:** [July 9, 2025, 9:16pm UTC](https://www.phphelp.com/t/recursivedirectoryiterator-and-recursiveiteratoriterator/36507 "2025-07-09T21:16:41Z")

</div>

In reference to this posting I could use a little help with RecursiveDirectoryIterator. The function as posted originally in the other thread is now obsolete so below is the new one which is working except for the first …

---

## [Listing Subfolders](https://www.phphelp.com/t/listing-subfolders/36506)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 5\
**Last updated:** [July 3, 2025, 5:08pm UTC](https://www.phphelp.com/t/listing-subfolders/36506 "2025-07-03T17:08:02Z")

</div>

This basic function called listFolders() is working well enough and builds upon an existing function that I’ve been using for quote a while called buildPath(). BuildPath() which I included for reference is simply fed a r…

---

## [Dynamically Loading Files Loses Variables](https://www.phphelp.com/t/dynamically-loading-files-loses-variables/36505)

<div class="topic-metadata">

**Author:** [@PCHome](https://www.phphelp.com/u/PCHome)\
**Replies:** 4\
**Last updated:** [June 28, 2025, 4:38pm UTC](https://www.phphelp.com/t/dynamically-loading-files-loses-variables/36505 "2025-06-28T16:38:00Z")

</div>

I created a function a while back as an experiment that works in either loading whichever files are included in $siteFiles as a comma-separated list in the path defined in $sitePath or excludes the files in the list. Th…

[Next page](https://www.phphelp.com/c/general-php-help/5.md?page=1)
