/    Sign up×
Community /Pin to ProfileBookmark

Hey all,

Got a question.. is there anyway you can have a HTML code that you created ie: <blah>… and have PHP grab it and replace it with something.. Now I know thats possible.. however is it possible for something like <show select=list> and have PHP pick up on the HTML <show>.. Then notice select is present and select LIST from a mysql table? I would like for this to be universal and PHP to know what its doing, otherthan coding LIST into the PHP. So I want the PHP to automatically detect LIST… Much Appreciated! ?

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryJan 30.2005 — Perhaps you could use a template engine such as [url=http://smarty.php.net/]Smarty[/url].

Adam
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — [i]Originally posted by AdamGundry [/i]

[B]Perhaps you could use a template engine such as [url=http://smarty.php.net/]Smarty[/url].



Adam [/B]
[/QUOTE]


<_<... My ass.. The whole point of this is to make a CMS... Is there any possible way to do what im asking, besides some third party PHP app..????
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — i would recommend using the template system from phpbb, it uses comments to dictate output

block var example&lt;!-- BEGIN (this.that) --&gt;
{this.that.name}&lt;br /&gt;
{this.that.desc}
&lt;!-- END (this.that) --&gt;
var example{MY_VAR}

[upl-file uuid=d2fe8747-a3af-4a60-a1f5-60786215af1b size=14kB]template.txt[/upl-file]
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — [i]Originally posted by ShrineDesigns [/i]

[B]i would recommend using the template system from phpbb, it uses comments to dictate output

block var example
&lt;!-- BEGIN (this.that) --&gt;
{this.that.name}&lt;br /&gt;
{this.that.desc}
&lt;!-- END (this.that) --&gt;
var example{MY_VAR} [/B][/QUOTE]

um... alright whatever.. screw this topic.. No Offense, but I was just looking for some pregreplace that could detect vars inside of a HTML code.. :-!.. NVM it thou.. Ill figure it out sooner or later...
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — preg_replace("/<show>(.+)</show>/i", "<b>1</b>", $html_page);
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — [i]Originally posted by ShrineDesigns [/i]

[B]preg_replace("/<show>(.+)</show>/i", "<b>1</b>", $html_page); [/B][/QUOTE]
alright, now were getting somewhere.. I want the Pregreplace to find <show what=fields> and look up the contents of 'what' and then grab a MySQL table depending on 'what' is equal to... ok? LOL
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — try[code=php]<?php
if(preg_match("/<shows+(\w)\s*\=\s*[\"\\']?(\w)[\"\\']?>(.+)</show>/i" $html_page, $matches))
{
$field = $matches[0][1];
$value = $matches[0][2];
$result = mysql_query("SELECT * FROM table WHERE $field = '$value'");
$row = mysql_fetch_array($result, 2);
$row = implode("<br />n", $row);
preg_replace("/" . $matches[0][3] . "/i", $row, $html_page);
}
?>[/code]
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — [i]Originally posted by ShrineDesigns [/i]

[B]try[code=php]<?php
if(preg_match("/<shows+(\w)\s*\=\s*[\"\\']?(\w)[\"\\']?>(.+)</show>/i" $html_page, $matches))
{
$field = $matches[0][1];
$value = $matches[0][2];
$result = mysql_query("SELECT * FROM table WHERE $field = '$value'");
$row = mysql_fetch_array($result, 2);
implode("<br />n", $row);
preg_replace("/" . $matches[0][3] . "/i", $row, $html_page);
}
?>[/code]
[/B][/QUOTE]
Finnaly man, you came through! Lots of thanks! hehe.. neways I need to understand it before i can cutsomize it :-) but thanks!!!
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — no problem
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — [i]Originally posted by ShrineDesigns [/i]

[B]try[code=php]<?php
if(preg_match("/<shows+(\w)\s*\=\s*[\"\\']?(\w)[\"\\']?>(.+)</show>/i" $html_page, $matches))
{
$field = $matches[0][1];
$value = $matches[0][2];
$result = mysql_query("SELECT * FROM table WHERE $field = '$value'");
$row = mysql_fetch_array($result, 2);
$row = implode("<br />n", $row);
preg_replace("/" . $matches[0][3] . "/i", $row, $html_page);
}
?>[/code]
[/B][/QUOTE]
alright man, im extreemly confused on the preg_match.. does a * represent anything? Like wildcard? yeah guess so.. ok but whats with all the backslashes.. and random letters!?!? ><... BTW.. im kinda a newbie.. learning as I go..
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — it wont work ?
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — see: [url=http://www.php.net/manual/en/reference.pcre.pattern.syntax.php]PCRE regex syntax[/url]

try[code=php]<?php
$txt = "<show color="pink">adafdf</show>";

if(preg_match("/<shows\s*color\=[\"\\']?([a-z0-9\#]+)[\"\\']?>(.+)</show>/i", $txt, $matches))
{
$txt = preg_replace("/show/i", "font", $txt);
$txt = str_replace($matches[0][1], "adfad", $txt);
}
echo $html_page;
?>[/code]
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 30.2005 — a;right, that didnt work... lets simplify this for me and you.. How can you grab a wildcard in a string and set it as a variable in PHP.. haha, i think that is exactly what I am trying to do..
Copy linkTweet thisAlerts:
@ShrineDesignsJan 30.2005 — there is no one wildcard in regexp, but the closes one would be: [b].[/b]

see for assigning variables:

http://www.php.net/manual/en/language.variables.variable.php

and/or

http://www.php.net/manual/en/language.variables.php
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 31.2005 — ok, I went to the URLS.. I know how to set a varible.. But i want a part of a string.. like <blah dfadf=sdfads>.. I want the PHP to pick up dfadf and set a variable to the contents of dfadf.. understnad?
[i]Originally posted by ShrineDesigns [/i]

[B]there is no one wildcard in regexp, but the closes one would be: [b].[/b]



see for assigning variables:

http://www.php.net/manual/en/language.variables.variable.php

and/or

http://www.php.net/manual/en/language.variables.php [/B]
[/QUOTE]
Copy linkTweet thisAlerts:
@ShrineDesignsJan 31.2005 — like: $attribute_name = attribute_value

[code=php]<?php
$html = "<show attribute="value"></show>
<show test="hello world"></show>";

if(preg_match_all("/<\w+\s+([a-z0-9\-_]+)=\"([^<>\"]+)">.*<\/\w+>/i", $html, $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
list(, $k, $v) = $match;
// echo "{$k} = {$v};n";
$$k = $v;
}
}
?>[/code]
Copy linkTweet thisAlerts:
@Kyleva2204authorJan 31.2005 — uh, do U mind if I IM ya?
[i]Originally posted by ShrineDesigns [/i]

[B]like: $attribute_name = attribute_value



[code=php]<?php
$html = "<show attribute="value"></show>
<show test="hello world"></show>";

if(preg_match_all("/<\w+\s+([a-z0-9\-_]+)=\"([^<>\"]+)">.*<\/\w+>/i", $html, $matches, PREG_SET_ORDER))
{
foreach($matches as $match)
{
list(, $k, $v) = $match;
// echo "{$k} = {$v};n";
$$k = $v;
}
}
?>[/code]
[/B][/QUOTE]
Copy linkTweet thisAlerts:
@ShrineDesignsJan 31.2005 — [code=php]<pre><?php
class xml
{
var $parser;
var $data;

function xml()
{
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
}
function parse($data)
{
xml_parse($this->parser, $data);
}
function tag_open($parser, $tag, $attributes)
{
foreach($attributes as $k => $v)
{
eval("$this->data->".$tag."->".$k."='".$v."';");
}
}
function tag_close($parser, $tag)
{
return;
}
}
$xml = new xml;
$data = <<<XML
<root>
<tag id="1" value="hello world" />
<tag id="2" />
<tag name="foo" />
<foo bar="woot"></foo>
</root>
XML;

$xml->parse($data);
print_r($xml->data);
?></pre>[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsJan 31.2005 — here

[upl-file uuid=7c9393f0-9ca4-44ca-8b36-c129d4c4b253 size=748B]file.txt[/upl-file]
×

Success!

Help @Kyleva2204 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...