[Solved] Php: how to access object individual elements [closed]

You can access the date value in two different ways. Number one: Use __toString() echo $var->__toString(); // or echo (string)$var; Number two: Use the DateTime format method: echo $var->format(‘Y-m-d H:i:s’); solved Php: how to access object individual elements [closed]

[Solved] Regular expression match against a string (blue:bar AND darkblue:foo) to darkblue

These are some patterns that I have written that work (in order of least efficient to most efficient in terms of “step count”): Step counts are based on this sample input: (green:bar AND black:foo) (blue:bar AND darkblue:foo) (yellow:bar AND grey:foo) (greengarden:bar AND red:foo) /(?:red|blue|green)(*SKIP)(*FAIL)|[a-z]+(?=:)/ Demo (513 steps) /\b(?!red:|blue:|green:)[a-z]+(?=:)/ Demo (372 steps) /(?<=\(|AND )(?!red:|blue:|green:)[^:]*/ Demo (319 … Read more

[Solved] Explain the PHP code & exit() function [closed]

PHP will create your function regardless of the exit(). Then, you call writeName() before the exit(); so it behaves as expected. (outputs and dies) try this: <?php echo “My name is “; writeName(); exit(); echo ‘I am still alive!’; function writeName() { echo “JEWEL AHMMED”; } and the “I am still alive!” will not be … Read more

[Solved] Can’t insert data into mysql database using PHP [closed]

Edited: Try just adding this code: <?php $message = mysql_real_escape_string(bbcode_to_html($message)); $sqlquery1 = ‘insert into topics (id_parent, id, id_user, title, message, id_author, timestamp, timestamp_user) select “‘ . $dn1[‘id_parent’] . ‘”, “‘ . $id . ‘”, max(id_user)+1, “”, “‘ . $message . ‘”, “‘ . $_SESSION[‘userid’] . ‘”, “‘ . time() . ‘”, “‘ . time() . … Read more

[Solved] php class error, it wont echo teacher [closed]

As people have mentioned in the comments, your code is filled with all sorts of errors. What I believe you want is this: class Person { function __construct($firstname,$lastname,$age) { $this->isAlive = true; $this->firstname = $firstname; $this->lastname = $lastname; $this->age = $age; } } $teacher = new Person(“boring”, “12345”, 12345); $student = new Person(“boringw”, “12345w”, 12345); … Read more

[Solved] How to strip parts of the given url using preg_replace (php) [closed]

For this specific case, you don’t need a regular expression, you can just parse the url $url=”http://dev.time.com/wp-content/uploads/2014/08/sheep-shrek-300×199.jpg?w=360″; $parts = parse_url($url); echo $parts[‘host’] . $parts[‘path’]; Missed that you want to strip the size … $data = preg_replace(‘/(-\d+x\d+)\.jpg/’, ‘.jpg’, $data); 1 solved How to strip parts of the given url using preg_replace (php) [closed]

[Solved] how do json decode in php?

PHP’s JSON functions are documented here: http://us3.php.net/json The json_decode() function may be especially useful: http://us3.php.net/manual/en/function.json-decode.php solved how do json decode in php?

[Solved] PHP function with looping variabel [closed]

You can define functions in a loop like this: for ($i=1; $i<=2; $i++) { $code = <<<EOD function writeMsg{$i}() { echo ‘Hello World!’; } EOD; eval($code); } writeMsg1(); It outputs: Hello World! This code uses a heredoc syntax (<<<EOD EOD;) to define the function and the eval() function which evaluates the code. 0 solved PHP … Read more

[Solved] Deprecated: Function ereg_replace() is deprecated [closed]

The function ereg_replace() is deprecated, that means that it is no longer supported by PHP by a particular reason (can be security or performance reasons, for example). Instead, use preg_replace(). You also need to replace the regular expression string [ ]{2,} to /[ ]{2,}/ Read more about pattern delimiters. 2 solved Deprecated: Function ereg_replace() is … Read more

[Solved] What is the purpose of $connect in mysqli_real_escape_string($connect, $username)? [closed]

Per the docs: Security: the default character set The character set must be set either at the server level, or with the API function mysqli_set_charset() for it to affect mysqli_real_escape_string(). See the concepts section on character sets for more information. And therein lies the reason for having the connection: how to escape your string depends … Read more

[Solved] Redirect to another URL in PHP [closed]

Once you have submitted your form, you will neded to detect the form submission and redirect using header() before any HTML output. Place this at the top of your page (presuming that you are in a php file) before your opening <html>: <?php if ((isset($_GET[‘site’])) && ($_GET[‘site’] != ”)){ header(“Location: “.$_GET[‘site’]); exit; } ?> 1 … Read more