Probably everything in my opinion!
I basically don't know what I'm doing. I've never written a .cgi file before, but I did write the script basing myself on several tutorials...
One of them is this one...
http://www.yourhtmlsource.com/cgi/processingforms.html
I want a Perl script that will process an html form, collect the user's data and send to email with a return Thank you.html file to user when they hit SUBMIT.
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
#pairs = split(/&/, $buffer);
foreach $pair (#pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
if( $FORM{magazine} ){
$magazine_flag ="ON";
}else{
$magazine_flag ="OFF";
}
if( $FORM{internet} ){
$internet_flag ="ON";
}else{
$internet_flag ="OFF";
}
if( $FORM{distributor} ){
$distributor_flag ="ON";
}else{
$distributor_flag ="OFF";
}
if( $FORM{yes1} ){
$yes1_flag ="ON";
}else{
$yes1_flag ="OFF";
}
if( $FORM{no1} ){
$no1_flag ="ON";
}else{
$no1_flag ="OFF";
}
if( $FORM{twofifty} ){
$twofifty_flag ="ON";
}else{
$twofifty_flag ="OFF";
}
if( $FORM{fivehundred} ){
$fivehundred_flag ="ON";
}else{
$fivehundred_flag ="OFF";
}
if( $FORM{thousand} ){
$thousand_flag ="ON";
}else{
$thousand_flag ="OFF";
}
if( $FORM{twofivehundred} ){
$twofivehundred_flag ="ON";
}else{
$twofivehundred_flag ="OFF";
}
if( $FORM{fivethousand} ){
$fivethousand_flag ="ON";
}else{
$fivethousand_flag ="OFF";
}
if( $FORM{tenthousand} ){
$tenthousand_flag ="ON";
}else{
$tenthousand_flag ="OFF";
}
if( $FORM{fifteenthousand} ){
$fifteenthousand_flag ="ON";
}else{
$fifteenthousand_flag ="OFF";
}
if( $FORM{yes2} ){
$yes2_flag ="ON";
}else{
$yes2_flag ="OFF";
}
if( $FORM{no2} ){
$no2_flag ="ON";
}else{
$no2_flag ="OFF";
}
if( $FORM{yes3} ){
$yes3_flag ="ON";
}else{
$yes3_flag ="OFF";
}
if( $FORM{no3} ){
$no3_flag ="ON";
}else{
$no3_flag ="OFF";
}
$Magazine-name = $FORM{magazine-name};
$Name = $FORM{name};
$Title = $FORM{title};
$Job = $FORM{job};
$Company = $FORM{company};
$Address = $FORM{address};
$City = $FORM{city};
$State = $FORM{state};
$Zip = $FORM{zip};
$Telephone = $FORM{telephone};
$E-mail = $FORM{e-mail};
open (MESSAGE,"| /usr/sbin/sendmail -t");
print MESSAGE "To: aalmeida\#aemc.com\n";
print MESSAGE "From: " . $Name . ", reader\n";
print MESSAGE "Reply-to: " . $E-mail . "(" . $Name . ")\n";
print MESSAGE "Subject: NECA 2013 Registration to win from $Name \n\n";
print MESSAGE "$Name wrote:\n\n";
print MESSAGE "Where do you look most often for test instrumentation?:\n\n";
print MESSAGE "$magazine_flag\n\n";
print MESSAGE "$magazine-name\n\n";
print MESSAGE "$internet_flag\n\n";
print MESSAGE "$distributor_flag\n\n";
print MESSAGE "$representative_flag\n\n";
print MESSAGE "I have a need for insulation testing:\n\n";
print MESSAGE "$yes1_flag\n\n";
print MESSAGE "$no1_flag\n\n";
print MESSAGE "What test voltage is important?:\n\n";
print MESSAGE "$twofifty_flag\n\n";
print MESSAGE "$fivehundred_flag\n\n";
print MESSAGE "$thousand_flag\n\n";
print MESSAGE "$twofivehundred_flag\n\n";
print MESSAGE "$fivethousand_flag\n\n";
print MESSAGE "$tenthousand_flag\n\n";
print MESSAGE "$fifteenthousand_flag\n\n";
print MESSAGE "Is the ability to store test results from the
instrument important?:\n\n";
print MESSAGE "$yes2_flag\n\n";
print MESSAGE "$no2_flag\n\n";
print MESSAGE "Do you plan to purchase within the next 6 months?:\n\n";
print MESSAGE "$yes3_flag\n\n";
print MESSAGE "$no3_flag\n\n";
print MESSAGE "Name: $FORM{name}\n\n";
print MESSAGE "Title: $FORM{title}\n\n";
print MESSAGE "Job Function: $FORM{job}\n\n";
print MESSAGE "Company: $FORM{company}\n\n";
print MESSAGE "Address: $FORM{address}\n\n";
print MESSAGE "City: $FORM{city}\n\n";
print MESSAGE "State: $FORM{state}\n\n";
print MESSAGE "Zip: $FORM{zip}\n\n";
print MESSAGE "Telephone: $FORM{telephone}\n\n";
print MESSAGE "E-mail: $FORM{e-mail}\n\n";
close (MESSAGE);
exit(0);
When I hit submit from the browser, I get this error:
Software error:
Can't modify subtraction (-) in scalar assignment at \boswinfs05\home\users\web\b465\whl.caadmin\www\HTML-email\SP_ToolKitPROMO_NECA2013\functions\formmailer.cgi line 117, near "};"
Missing right curly or square bracket at \boswinfs05\home\users\web\b465\whl.caadmin\www\HTML-email\SP_ToolKitPROMO_NECA2013\functions\formmailer.cgi line 180, at end of line
syntax error at \boswinfs05\home\users\web\b465\whl.caadmin\www\HTML-email\SP_ToolKitPROMO_NECA2013\functions\formmailer.cgi line 180, at EOF
Execution of \boswinfs05\home\users\web\b465\whl.caadmin\www\HTML-email\SP_ToolKitPROMO_NECA2013\functions\formmailer.cgi aborted due to compilation errors.
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
How can I make the script work?
Any insight would be much appreciated or links to more in depth tutorials would also be great.
Thanks!
You are using hyphens in those identifiers.
$Magazine-name = $FORM{magazine-name};
$E-mail = $FORM{e-mail};
Change those to underscores.
Enable syntax highlighting in your editor. That will help you catch such errors quickly even before compiling.
$E-mail and $Magazine-name are not valid variable names. Only letters, numbers, and the underscore characters can be used in a variable name(*). Try $E_mail or $Email.
(*) - without a little symbol table wizardry or other hacks that leave an impression of Perl as a write-only language
Tips:
Always use use strict; use warnings;!
Use the following instead of handling the CGI yourself:
use CGI qw( );
my $cgi = CGI->new();
my $form = $cgi->Vars();
# Use $form->{...} instead of $FORM{...}
if( $form->{magazine} ){
$magazine_flag ="ON";
}else{
$magazine_flag ="OFF";
}
if( $form->{internet} ){
...
could be written as
$form->{$_} = $form->{$_} ? "ON" : "OFF"
for qw(
magazine
internet
...
);
Related
I am working on youtube api
and I want to get youtube video information using youtube video info JSON object
and I am using a code as given below but when I try to run this code it is showing error as "Video Is not cipher not needed to decode"
please help me to solve it out also tell me where is the problem in code
<?php
// Video with cipher signature
$video_id = "zDrNLZ1uJ2w";
// get_video_info url formation
// although for cipher signature we have to get the details from the video's webapge not from get_video_info object
$info_url = "http://www.youtube.com/get_video_info?el=detailpage&asv=3&video_id=".$video_id;
// youtube webpage url formation
$yt_url = 'http://www.youtube.com/watch?v='.$video_id.'&gl=US&persist_gl=1&hl=en&persist_hl=1';;
// get the contents from the url
$raw_data = file_get_contents($info_url);
// parse the data received and save it as an array
$output = array();
parse_str($raw_data,$output);
// check the status of the get_video_info object
if($output['status']=='ok'){
// check for the cipher signature
$cipher = (isset($output['use_cipher_signature']) && $output['use_cipher_signature']=='True') ? true : false;
// If cipher is true then we have to decode it
if($cipher == true){
// if cipher is true then we have to change the plan and get the details from the video's youtube wbe page
$yt_html = file_get_contents($yt_url);
// parse for the script containing the configuration
preg_match('/ytplayer.config = {(.*?)};/',$yt_html,$match);
$yt_object = #json_decode('{'.$match[1].'}') ;
/// check if we are able to parse data
if(!is_object($yt_object)){
echo 'Sorry! Unable to parse Data';
}else{
// parse available formats
$formats = $yt_object->args->url_encoded_fmt_stream_map;
// get the player id from assets section
$player_id = strbtwn($yt_object->assets->js,'html5player-','.js');
$player_id = explode("/", $player_id);
$player_id = $player_id[0];
echo 'Player ID: '.$player_id.'<br /><hr />';
// get the algo dictionary
// first check if the file exists
if(file_exists('./algo.json'))
$algos = json_decode(file_get_contents('algo.json'),true);
else{
// API call to fetch the algo dictionary
$algos_dict = file_get_contents("http://api.gitnol.com/getAlgo.php?playerID=".$player_id);
// saving the algo dictonary in local env for easy access
// Note: Developers should save the dictionary in their local env.
// Only make the API call for the new player ids which is not present in the algo dictionary.
// Repeated violation will results in IP ban.
file_put_contents('algo.json', $algos_dict);
$algos = json_decode($algos_dict,true);
}
/// check if the algo exist for the given player id
if(!array_key_exists($player_id, $algos)){
// if the algo dictionary is old then fetch a new one
$algos_dict = file_get_contents("http://api.gitnol.com/getAlgo.php?playerID=".$player_id);
file_put_contents('algo.json', $algos_dict);
$algos = json_decode($algos_dict,true);
$algo = $algos[$player_id][1];
}else{
$algo = $algos[$player_id][1];
}
echo 'Algo Used: '.$algo.'<br /><hr />';
// download links formation
$dlinks = array();
$links = explode(',',$formats);
echo 'Download links <br /><br />';
foreach ($links as $link) {
parse_str($link,$linkarr);
// parse link array one by one and decrypt the signature
$dlinks[$linkarr['itag']] = $linkarr['url'] . "&signature=" . decrypt($linkarr['s'],$algo);
echo $linkarr['itag'].'<br />';
echo $dlinks[$linkarr['itag']].'<br /><br />';
}
echo '<hr />';
}
}else{
echo 'Video Is not cipher not needed to decode';
}
}else{
echo 'Unable to get Video Info';
}
// string helper function
function strbtwn($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
// signature decoding
// parse the python string operation into php string operation
function decrypt($sig, $algo){
$funcarr = explode(' + ', $algo);
$decrypt = '';
foreach($funcarr as $singfunc){
$singfunc = substr($singfunc,2,-1);
$operators = explode(':', $singfunc);
if (sizeof($operators) == 1) {
$decrypt .= $sig[$operators[0]];
}
if (sizeof($operators) == 2) {
if($operators[0] == ''){
$decrypt .= substr($sig, 0 ,$operators[1]);
}
if($operators[1] == ''){
$decrypt .= substr($sig, $operators[0]);
}
if($operators[0] >= 0 && $operators[1] >= 0){
$decrypt .= substr($sig, $operators[0], $operators[1] - $operators[0]);
}
}
if (sizeof($operators) == 3) {
if($operators[0] == '' && $operators[1] == ''){
$decrypt .= strrev($sig);
}
if($operators[0] >=0 && $operators[1] == '' && $operators[0] != ''){
$decrypt .= strrev(substr($sig, 0, $operators[0] + 1));
}
if($operators[0] >=0 && $operators[1] >= 0 && $operators[0] != '' && $operators[1] != ''){
$decrypt .= strrev(substr($sig, $operators[1] + 1, $operators[0] - $operators[1]));
}
}
}
return $decrypt;
}
?>
According to your code $cipher is being set to false because 'use_cipher_signature' is not found in the $raw_data from file_get_contents($info_url).
I have atable in mysql database i'm fetching it to a html
print "<table>\n";
$result = $con->query($query); //return only the first row (we only need field names)
$row = $result->fetch(PDO::FETCH_ASSOC);
print "<tr>\n";
foreach ($row as $field => $value){
print "<th>$field</th>\n";
} // end foreach
print "</tr>\n"; //second query gets the data
$data = $con->query($query);
$data->setFetchMode(PDO::FETCH_ASSOC);
foreach($data as $row){
print " <tr>\n";
foreach ($row as $name=>$value){
print "<td>$value</td>\n";
} // end field loop
print "</tr>\n"; } // end record loop
print "</table>\n";
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} // end try
i have 2 columns that have a boolean value, i want that if column 6 = '0' then display x color:red; else display ✔ color:green;
Final Code
foreach ($row as $name=>$value){
if (($name == "paid" || $name == "added") && $value == "0"){
print "<td><span style='color: red;'>X</span></td>\n";
}
elseif (($name == "paid" || $name == "added") && $value == "1"){
print "<td><span style='color: lime;'>✔</span></td>\n";
}
else {
print "<td>$value</td>\n";
}
} // end field loop
Try:
foreach ($row as $name=>$value){
if ($name == "Column 6"){
if ($value == "0") {
print "<td><span style='color: red;">X</span></td>\n";
}
else {
print "<td>✔</td>\n";
}
}
else {
print "<td>$value</td>\n";
}
} // end field loop
There's no good way to colorize checkboxes, unless you want to use some complex css. However you could try and utilize before and after CSS for checkboxes as shown here: CSS ''background-color" attribute not working on checkbox inside <div>
I have a script that allows me to convert a database from MySQL to Excel .xls format, It was a success,
here is the code
<?php
// DB TABLE Exporter
//
// How to use:
//
// Place this file in a safe place, edit the info just below here
// browse to the file, enjoy!
// CHANGE THIS STUFF FOR WHAT YOU NEED TO DO
$cdate = date("Y-m-d");
$dbhost = "localhost";
$dbuser = "-";
$dbpass = "-";
$dbname = "-";
$dbtable = "-";
$filename = "C:\xxx";
// END CHANGING STUFF
// first thing that we are going to do is make some functions for writing out
// and excel file. These functions do some hex writing and to be honest I got
// them from some where else but hey it works so I am not going to question it
// just reuse
// This one makes the beginning of the xls file
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
// This one makes the end of the xls file
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
// this will write text in the cell you specify
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
// make the connection an DB query
$dbc = mysql_connect( $dbhost , $dbuser , $dbpass ) or die( mysql_error() );
mysql_select_db( $dbname );
$q = "SELECT * FROM ".$dbtable." ";
$qr = mysql_query( $q ) or die( mysql_error() );
//start the object
ob_start();
// start the file
xlsBOF();
// these will be used for keeping things in order.
$col = 0;
$row = 0;
// This tells us that we are on the first row
$first = true;
while( $qrow = mysql_fetch_assoc( $qr ) )
{
// Ok we are on the first row
// lets make some headers of sorts
if( $first )
{
// di comment karena ini ngasih label tabelnya, sepertinya nggak butuh
//foreach( $qrow as $k => $v )
//{
// // take the key and make label
// // make it uppper case and replace _ with ' '
// xlsWriteLabel( $row, $col, strtoupper( ereg_replace( "_" , " " , $k ) ) );
// $col++;
//}
// prepare for the first real data row
$col = 0;
$row = 0;//$row++; // nyoba
$first = false;
}
// go through the data
foreach( $qrow as $k => $v )
{
// write it out
xlsWriteLabel( $row, $col, $v );
$col++;
}
// reset col and goto next row
$col = 0;
$row++;
}
xlsEOF();
//write the contents of the object to a file
file_put_contents($filename, ob_get_clean());
?>
this code produced a .xls file. I used Matlab to read my .xls file through readxls function, but it didn't recognize the value inside the .xls file as a numeric data, so my script on matlab couldn't make a matrix from reading my xls file. I had to convert it manually inside excel, there were some pop-ups near the value that offers me to convert it into numbers
If your goal is to take data from MySQL and put it in Matlab it might be easier to directly connect to MySQL from Matlab rather than sending the data through the xls format.
http://www.mathworks.com/help/database/ug/database.fetch.html
My php form has a <select> option for multiple recipients with an email address associated to each of them:
<select name="sendto">
<option value="select">-- Select --</option>
<option value="general">General</option>
<option value="support">Support</option>
<option value="sales">Sales</option>
</select>
I'm able to send and receive successfully only the 'General' option, the rest fails. It's obvious the issue is with the 'if statement' but I can't figure out what the problem is exactly. Any help? Thanks.
This is the php code:
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply#my-site.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.my-site.com";
if ($sendto == 'general') {
$to = 'alex#my-site.com';
}
else if ($sendto == 'support') {
$to = 'alabanino#my-site.com';
}
else if ($sendto == 'sales') {
$to = 'alabanino#my-site.com';
}
else { //other options
$to = 'alex#my-site.com';
}
if($from == '') { print "You have not entered an email, please go back and try again"; }
else {
if($name == '') { print "You have not entered a name, please go back and try again"; }
else {
$send = mail($to, $subject, $body, $headers, '-fnoreply#yourmailer.com');
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send){
header( "Location: http://www.my-site.com/thankyou.html" );}
else {
print "We encountered an error sending your mail, please notify webmaster#my-site.com";
}
}
}
?>
Where is $sento defined? This will be 'working' cos it will be defaulting to your final else condition as all others fail.
You need to add this and it should work
$sendto = $_REQUEST['sendto']
Or else use $to insetad
I've got a variable which is formatted with random HTML code. I call it to {$text} and i truncate it.
The value is for example:
<div>Lorem <i>ipsum <b>dolor <span>sit </span>amet</b>, con</i> elit.</div>
If i truncate the text's first ~30 letters, I'll get this:
<div>Lorem <i>ipsum <b>dolor <span>sit
The problem is, I can't close the elements. So, I need a script, which check the <*> elements in the code (where * could be anything), and if it dont have a close tag, close 'em.
Please help me in this. Thanks.
Solution after hours, and 4 vote-up # stackoverflow:
PHP:
...
function closetags($content) {
preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $content, $result);
$openedtags = $result[1];
preg_match_all('#</([a-z]+)>#iU', $content, $result);
$closedtags = $result[1];
$len_opened = count($openedtags);
if (count($closedtags) == $len_opened) {
return $content;
}
$openedtags = array_reverse($openedtags);
for ($i=0; $i < $len_opened; $i++) {
if (!in_array($openedtags[$i], $closedtags)) {
$content .= '</'.$openedtags[$i].'>';
} else {
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
}
}
return $content;
}
...
the TPL:
{$pages[j].text|truncate:300|#closetags}
Pull out all the open tags, push them into an array (array_1) one-by-one.
Pull out all of the closed tags, push them into an array (array_2) one-by-on (this includes self closing tags).
For the tags in the first array (array_1) that are not found in the second array (array_2), add them to the html.
[edit]
Of course, this method fails miserably if you do not write proper html... but whatchagonnado?
Another way would be to look ahead in the string to see which tags are closed and close them as needed.
To simplify, if the code is valid XML before truncating and you don't cut off tags in half, the algorithm would be something like this:
Push opening tags onto a stack
Pop them off when you find the closing tag (which will match if the code is valid)
When you get to the end, start popping to create closing. The remaining tags should be appended to the original (truncated) text.
Example:
<div>Lorem <i>ipsum <b>dolor <span>sit </span>amet</b><div>
Push "div","i","b","span"
Found closing tag "span"
Pop "span"
Found closing tag "b"
Pop "b"
Push "div"
End of truncated text
Pop "div" --> add </div> to text
Pop "b" --> add </b> to text
Pop "i" --> add </i> to text
Pop "div" --> add </div> to text
End
for other people like me and you I found this code ,I think is a better solution
add this file named "modifier.html_substr.php"
<?php
/*
* Smarty plugin
*
-------------------------------------------------------------
* File: modifier.html_substr.php
* Type: modifier
* Name: html_substr
* Version: 1.0
* Date: June 19th, 2003
* Purpose: Cut a string preserving any tag nesting and matching.
* Install: Drop into the plugin directory.
* Author: Original Javascript Code: Benjamin Lupu <hide#address.com>
* Translation to PHP & Smarty: Edward Dale <hide#address.com>
* Modification to add a string: Sebastian Kuhlmann <hide#address.com>
* Modification to put the added string before closing <p> or <li> tags by Peter Carter http://www.podhawk.com
-------------------------------------------------------------
*/
function smarty_modifier_html_substr($string, $length, $addstring="")
{
//some nice italics for the add-string
if (!empty($addstring)) $addstring = "<i> " . $addstring . "</i>";
if (strlen($string) > $length) {
if( !empty( $string ) && $length>0 ) {
$isText = true;
$ret = "";
$i = 0;
$currentChar = "";
$lastSpacePosition = -1;
$lastChar = "";
$tagsArray = array();
$currentTag = "";
$tagLevel = 0;
$addstringAdded = false;
$noTagLength = strlen( strip_tags( $string ) );
// Parser loop
for( $j=0; $j<strlen( $string ); $j++ ) {
$currentChar = substr( $string, $j, 1 );
$ret .= $currentChar;
// Lesser than event
if( $currentChar == "<") $isText = false;
// Character handler
if( $isText ) {
// Memorize last space position
if( $currentChar == " " ) { $lastSpacePosition = $j; }
else { $lastChar = $currentChar; }
$i++;
} else {
$currentTag .= $currentChar;
}
// Greater than event
if( $currentChar == ">" ) {
$isText = true;
// Opening tag handler
if( ( strpos( $currentTag, "<" ) !== FALSE ) &&
( strpos( $currentTag, "/>" ) === FALSE ) &&
( strpos( $currentTag, "</") === FALSE ) ) {
// Tag has attribute(s)
if( strpos( $currentTag, " " ) !== FALSE ) {
$currentTag = substr( $currentTag, 1, strpos( $currentTag, " " ) - 1 );
} else {
// Tag doesn't have attribute(s)
$currentTag = substr( $currentTag, 1, -1 );
}
array_push( $tagsArray, $currentTag );
} else if( strpos( $currentTag, "</" ) !== FALSE ) {
array_pop( $tagsArray );
}
$currentTag = "";
}
if( $i >= $length) {
break;
}
}
// Cut HTML string at last space position
if( $length < $noTagLength ) {
if( $lastSpacePosition != -1 ) {
$ret = substr( $string, 0, $lastSpacePosition );
} else {
$ret = substr( $string, $j );
}
}
// Close broken XHTML elements
while( sizeof( $tagsArray ) != 0 ) {
$aTag = array_pop( $tagsArray );
// if a <p> or <li> tag needs to be closed, put the add-string in first
if (($aTag == "p" || $aTag == "li") && strlen($string) > $length) {
$ret .= $addstring;
$addstringAdded = true;
}
$ret .= "</" . $aTag . ">\n";
}
} else {
$ret = "";
}
// if we have not added the add-string already
if ( strlen($string) > $length && $addstringAdded == false) {
return( $ret.$addstring );
}
else {
return ( $ret );
}
}
else {
return ( $string );
}
}
?>
usage
{$yourdata|html_substr:300:' ...'}