Skip to content

Tag: php

How to print all properties of an object

I have an unknown object in php page. How can I print/echo it, so I can see what properties/values do it have? What about functions? Is there any way to know what functions an object have? Answer or These are the same things you use for arrays too. These will show protected and private properties of objects w…

MySQL select column length in php (below PHP7)

How do I get the actual max length of a specified column in php (prior to PHP7)? For instance, this table: id – int(11) name – string(20) I want in php to select the maximum number of characters that a field can have, like and it should then return 20 (since it’s the maximum number of charac…

Remove all attributes from html tags

I have this html code: How can I remove attributes from all tags? I’d like it to look like this: Answer Adapted from my answer on a similar question The RegExp broken down: Add some quoting, and use the replacement text <$1$2> it should strip any text after the tagname until the end of tag /> o…

PHP Linefeeds (n) Not Working

For some reason I can’t use n to create a linefeed when outputting to a file with PHP. It just writes “n” to the file. I’ve tried using “\n” as well, where it just writes “n” (as expected). But I can’t for the life of me figure out why adding n to my strin…

Get the index of a certain value in an array in PHP

I have an array: I want to get the index for a given value (i.e. 1 for string2 and 2 for string3) All I want is the position of the strings in the array string1 is 0 string2 is 1 string3 is 2 How to achieve this? Answer array_search is the way to do it. array_search ( mixed $needle ,

Sanitize user-supplied URL for file_get_contents

I want to use file_get_contents to implement a proxy so I can do cross domain AJAX requests. Query string will be used to supply the URL to file_get_contents. Now the problem is people can muck around with the query string in order to read local files on the server. I don’t want this. Can someone get me…