Cant echo preg_match_all as it needed - php

I have an XML file with the following content:
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="ALALALAL"><vt:lpwstr>asdasda</vt:lpwstr></property><property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="3" name="MACABSZ"><vt:lpwstr>ooooo</vt:lpwstr></property><property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="4" name="3"><vt:lpwstr>c</vt:lpwstr></property><property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="5" name="4"><vt:lpwstr>d</vt:lpwstr></property>
I have the following php. (I am able to fine desired parts of the xml):
if (preg_match_all ('_name="(.*?)"_', $ekker, $tomb2));
if (preg_match_all ('_<vt:lpwstr>(.*?)</vt:lpwstr>_', $ekker, $tomb));
In an html file I want to echo the results, so I use this:
<form>
<?php
foreach ($tomb2[1] as $metaname);
foreach ($tomb[1] as $talalat){
echo '<p>' . "$metaname\n" . '</p>' . '<br>' . '<input type="text" name="firstname" value="' . "$talalat\n" . '">' . '<br>';}?>
</form>
As a result I get this:
However this is not exactly what I want. Instead of the first three "4" I need: ALALALAL, MACABSZ, 3. Why does it echo only the last result of the 'name="(.*?)"' search?
Thanks for your answer!

From what I get, what you want is to access both arrays items with same index in one single loop. Maybe this will do :
<form>
<?php
foreach ($tomb2[1] as $key => $metaname){
$talalat = $tomb[1][$key];
echo '<p>' . "$metaname\n" . '</p>' . '<br>' . '<input type="text" name="firstname" value="' . "$talalat\n" . '">' . '<br>';
}
?>
</form>

Related

restrict future dates in HTML input using only PHP

I want to restrict date input in my form. I'm using PHP and HTML to code.
<?php
echo '<input type="date" name="doc" value="' . date("d-m-Y") . '" min="11-05-2014" max="' . date("d-m-Y") . '"/>';
?>
I've tried this post. It has a solution using jQuery, but I don't want to use jQuery.
<?php
echo '<input type="date" name="doc" value="' . date("Y-m-d") . '" min="2014-11-04" max="' . date("Y-m-d") . '"/>';
?>

Cant echo multiple values in array

I have something like this in my code:
<?php
foreach ($tomb2[1] as $key => $metaname){
$talalat = $tomb[1][$key];
echo '<p>' . "$metaname\n" . '</p>' . '<br>' . '<input type="text" name="metavalue[]" value="' . "$talalat\n" . '">' . '<br>';
}
?>
<input type="submit" name="Generálás" value="insert" onclick="insert()" />
</form>
I try to echo the several different values, however I get only the last one. Possibly the array contains only the last one. What am I doing wrong?
if you use a post method in form then you have to written $ertekek = $_POST["metavalue"] instead of $_GET["metavalue"] and then use print_r($ertekek)
instead of echo $ertekek;
You have written $talalat = $tomb[1][$key]; instead of $talalat = $tomb2[1][$key];

Twig extension function read value

I'm trying to create a set of simplified functions to let an user create a twig template that will be rendered as a form.
The form, when executed should read self generated data array.
The code below should print a field with name 'hello', when submitted (with example value 'world') create an array key hello and display the binded field with value 'world'.
Example template:
{{configkey('hello', 'Hello Field')}}
The extension function
$func = new Twig_SimpleFunction('configkey', function ($key='example', $label='label') {
echo '<div class="control-group">';
echo '<label class="control-label" for="' . $key . '">' . $label . '</label>';
echo '<div class="controls">';
echo '<input type="text" name="' . $key . '" value="{{config.' . $key . '}}"/>';
echo '</div>';
echo '</div>';
});
$this->_twigEnv->addFunction('configkey',$func);
the output
Thakns everyone for help but i found the solution easier than expected..
$func = new Twig_SimpleFunction('configkey', function ($key='example', $label='label', $value='') {
echo '<div class="control-group">';
echo '<label class="control-label" for="' . $key . '">' . $label . '</label>';
echo '<div class="controls">';
echo '<input type="text" name="' . $key . '" value="' . $value . '"/>';
echo '</div>';
echo '</div>';
});
The call will be
{{configkey('hello', 'Hello Field', config.hello)}}
Do you have a better aproach for the binding just using the key parameter ?

How to add own CSS to includeded form in PHP

I have proxy server powered on PHProxy 0.5b2 where is included mini url form. But there is an problem with CSS. Every visited page overwrite and overlap my own CSS.
I tried to add own style="" for every object but is not working (visited sites overwrite css).
My index.inc.php
if ($_flags['include_form'] && !isset($_GET['nf']))
{
$_url_form = '<div style="width:100%;margin:0;text-align:center;border-bottom:1px solid #725554;color:#000000;background-color:#F2FDF3;font-size:12px;font-weight:bold;font-family:Bitstream Vera Sans,arial,sans-serif;padding:4px;">'
. '<form method="post" action="' . $_script_url . '">'
. ' <label for="____' . $_config['url_var_name'] . '">Address:</label> <input id="____' . $_config['url_var_name'] . '" type="text" size="80" name="' . $_config['url_var_name'] . '" value="' . $_url . '" />'
. ' <input type="submit" name="go" value="Go" />'
. ' [go: up one dir, main page]'
. '<br /><hr />';
foreach ($_flags as $flag_name => $flag_value)
{
if (!$_frozen_flags[$flag_name])
{
$_url_form .= '<label><input type="checkbox" name="' . $_config['flags_var_name'] . '[' . $flag_name . ']"' . ($flag_value ? ' checked="checked"' : '') . ' /> ' . $_labels[$flag_name][0] . '</label> ';
}
}
$_url_form .= '</form></div>';
$_response_body = preg_replace('#\<\s*body(.*?)\>#si', "$0\n$_url_form" , $_response_body, 1);
}
Any help?
Thanks
Peter

PHP displays tags in different order

I have following problem, I have list of products in a database and want to display them in table unfortunately it plays some tricks for me because it displays one td before table even begins.
Here are the PHP functions:
<?php
function displayProduct($code,$url)
{
echo '<form method="post" action="cart_update.php"><input type="hidden" name="code" value="' . $code . '"/>';
echo '<input type="hidden" name="return_url" value="' . $url . '" />';
echo '<input type="hidden" name="type" value="add" /><input type="submit" value="Add" /></form>';
}
function displayItem($obj,$url)
{
echo '<tr>';
echo '<td>' . $obj->menuposition . '</td><td>' . $obj->name . '</td><td>' . '£'.$obj->price . '</td><td>' . displayProduct($obj->code,$url) .'</td>';
echo '</tr>';
if(strlen($obj->description) > 2)
{
echo '<tr><td colspan="4" style="font-size: 10px;">' . $obj->description . '</td></tr>';
}
}
?>
And here is the HTML output that I get:
Could someone help me ?
The echo call from displayProduct happens before the echo call of displayItem occurs.
I can see two solutions.
1: displayProduct should return the things to write and not echo them.
2:
echo '<td>' . $obj->menuposition . '</td><td>' . $obj->name . '</td><td>' . '£'.$obj->price . '</td><td>';
displayProduct($obj->code,$url);
echo '</td>';
displayProduct($code,$url) should return the string instead of printing it out:
function displayProduct($code,$url)
{
$result = '<form method="post" action="cart_update.php"><input type="hidden" name="code" value="' . $code . '"/>';
$result .='<input type="hidden" name="return_url" value="' . $url . '" />';
$result .='<input type="hidden" name="type" value="add" /><input type="submit" value="Add" /></form>';
return $result
}
[Edit] I should read better the questions...
But this still applies:
Also as Adrian stated, you should not echo the lines in "displayProducts", but return a string.

Categories