•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 375,235 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,028 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 407 | Replies: 8 | Solved
![]() |
is there a way to create a function that uses values from the statement inside of brackets.
ex.
if not, what i am trying to do is get a html tag and check/modify without having it inside of a variable or echo tag.
for example, i want to do the equivilent of this:
i do not want to use javascript for this although it would be easier.
thanks!
ex.
php Syntax (Toggle Plain Text)
myFunction(){ //data here }
if not, what i am trying to do is get a html tag and check/modify without having it inside of a variable or echo tag.
for example, i want to do the equivilent of this:
php Syntax (Toggle Plain Text)
<?php $data ={ ?> test <?php } myFunction($test); ?>
i do not want to use javascript for this although it would be easier.
thanks!
toast
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Rep Power: 1
Solved Threads: 19
Although the syntax of your example is incorrect, yes, you can create a function to manipulate the data.
eg.
eg.
PHP Syntax (Toggle Plain Text)
<?php function myFunction($input) { $output = strtolower($input); return $output; } $data = 'TEST'; $result = myFunction($data); echo $result; ?>
Last edited by Suomedia : Mar 28th, 2008 at 11:42 am.
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
•
•
•
•
if not, what i am trying to do is get a html tag and check/modify without having it inside of a variable or echo tag.
html Syntax (Toggle Plain Text)
<?php checkConfig(){ ?> <input type="text" name="input" /> <?php } ?>
i dont have issues with the "meat" of the function.
i will be constantly changing the data that i want to run through checkConfig() so putting the data in a variable ex. <?php $data="<input....."; ?> would not be efficient or helpful.
maby you can get the same results with a class?
Last edited by hunkychop : Mar 28th, 2008 at 12:32 pm.
toast
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Rep Power: 1
Solved Threads: 19
Anything that is outside PHP tags is not available to PHP to manipulate.
Its hard to understand exactly what you are trying to do - why do you wish to manipulate the HTML? What is "the configuration". What is "the data contained in a statement"?
Why not just have PHP output the correct HTML based on your "configuration"?
Matti Ressler
Suomedia
Its hard to understand exactly what you are trying to do - why do you wish to manipulate the HTML? What is "the configuration". What is "the data contained in a statement"?
Why not just have PHP output the correct HTML based on your "configuration"?
Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
i wrote the below script but it is not done
note: what i will eventually write is not as basic as just bolding the text. i just put that there as an example.
example check function
example data:
note: what i will eventually write is not as basic as just bolding the text. i just put that there as an example.
example check function
php Syntax (Toggle Plain Text)
<?php function check($d){ require('config.php'); // contains $boldtext = true; if($boldtext){ return "<b>".$d."</b>"; } }?>
example data:
php Syntax (Toggle Plain Text)
<?php class data{function get(){ ?>
html Syntax (Toggle Plain Text)
This is the text that will go through the check() function
php Syntax (Toggle Plain Text)
<?php } function ret($string){echo $string;}}$data = new data(); ?> <?php $data->ret(check($data->get())); ?>
Last edited by hunkychop : Mar 28th, 2008 at 4:01 pm.
toast
i dont need to "technicaly" or "directly" manipulate the html, i just need to grab the html and then echo it modified.
let me rephrase this...
when i run this....
<?php function test(){ ?>
data
<?php } ?>
everytime a run test() in php, the html outside of the tags is outputted (data)
i want to take the data in test() and be able to do anything with it that i could do with a normal string.
i DO NOT want to do this.
echo "html here..";
or
<?php
$data = <<<_
html here...
_;
echo $data;
?>
i want to have the text outside of the php tags, grab it, and put it into string so i can echo it later. I cant quite phrase why i need to have the origional html outside of the php tags but you will just have to trust me that it is what i want. I dont know if i am on the right track with using a function to get the data, but i cant find any other way to get it,
i have tried doing something like this: <?php function test(){ return ?>html here...<?php ; } ?>
but nothing is returned.
Thanks for your help so far.
let me rephrase this...
when i run this....
<?php function test(){ ?>
data
<?php } ?>
everytime a run test() in php, the html outside of the tags is outputted (data)
i want to take the data in test() and be able to do anything with it that i could do with a normal string.
i DO NOT want to do this.
echo "html here..";
or
<?php
$data = <<<_
html here...
_;
echo $data;
?>
i want to have the text outside of the php tags, grab it, and put it into string so i can echo it later. I cant quite phrase why i need to have the origional html outside of the php tags but you will just have to trust me that it is what i want. I dont know if i am on the right track with using a function to get the data, but i cant find any other way to get it,
i have tried doing something like this: <?php function test(){ return ?>html here...<?php ; } ?>
but nothing is returned.
Thanks for your help so far.
Last edited by hunkychop : Mar 28th, 2008 at 6:54 pm.
toast
i am sorry for the triple post, i truly am... but i solved this issue after a day's work of googling and thought i could save people the same trouble by posting my solution here. i guess a moderator could delete by past two posts or something.
any way...
i discovered the use of buffering data before it reaches the browser.
any way...
i discovered the use of buffering data before it reaches the browser.
php Syntax (Toggle Plain Text)
<?php //function that gets html function getHTML($container_function){ //johndm.com - gets html that results from //a function. example usage: // <?php function foo(){ ?|> bar <?php } ?|> // echo "<b>".getHTML("foo")."</b>"; ob_start();ob_clean(); //start buffer call_user_func($container_function); //call container function $data=ob_get_contents(); //get data ob_end_clean(); //remove output from function return $data; //return html } //example usage function foo(){ ?> <b>foo</b> <?php } $d=getHTML("foo"); //now that the html outputted by the //function is in a string, you can do anything //to it you could do to a string. echo "i am a ".$d." bar"; echo "<br />"; echo "i am ".strlen($d)." chars long"; echo "<br />"; echo "i have ".substr_count($d,">")." '>'s in me"; echo "<br />"; echo "my html looks like this: ".htmlentities($d); //not only can it get html that is not inside //of php tags, it can also let you modify //echo/printed data from a function also. ?>
Last edited by hunkychop : Mar 28th, 2008 at 8:09 pm.
toast
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Rep Power: 1
Solved Threads: 19
Perhaps something like this?
Matti Ressler
Suomedia
<?php
function myfunction($buffer) {
return str_replace('hello', 'goodbye', $buffer);
}
$mystuff = ob_start("myfunction");
?>
I am here to say hello
<?php
ob_end_flush();
?>Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- QBASIC and Visual Basic (Legacy and Other Languages)
- User defined functions (C++)
- User-Defined Function - part 2 (C++)
- @@ ListFuns.c @@ (C)
- Create Windows Authentication (VB.NET)
Other Threads in the PHP Forum
- Previous Thread: send email Undefined variable:
- Next Thread: function in php


Linear Mode