I need coding in PHP, remove symbols in Title

Status
Not open for further replies.

bestvideorap

Active Member
139
2011
6
0
Hi everyone,

What should I change to datalife engine or in themplate for automatically delete the title characters?
I have the following title: The.Name.Of.Title [2010]-Post

When public a post I would like these characters to be deleted automatically
Code:
.[ ]( )-

want these characters to be replaced automatically with space.

After posting showing: The Name Of Title 2010 Post

Payment by Paypal who wants to help me

Thanks!
 
16 comments
If you are looking for a PHP solution, here it is:

PHP:
$title = 'The.Name.Of.Title [2010]-Post';
// pattern
$pattern = '#[^a-zA-Z0-9]#';
$newTitle = preg_replace_callback($pattern, 'callback', $title);
// the callback function
function callback ($matches) {    
    return $matches[3].' '.$matches[2].' '.$matches[1];
}
echo $newTitle;
 
Last edited:
For function properly these files have changed on datalife:
/engine/modules/addnews.php
/engine/ajax/editnews.php
/engine/inc/addnews.php
/engine/inc/editnews.php
/engine/ajax/rebuild.php

I do not know exactly what changed in each file.

Thanks for answers!
 
I dont have access to DataLife Engine, post your files on pastebin and link in thread.

engine/modules/addnews.php
engine/inc/addnews.php

one file is for admin panel and other for user.
 
Open /engine/inc/addnews.php
At the end of file before ?> add this function

PHP:
// clean title 
function my_clean_title($title)
{   
    return preg_replace_callback('#[^a-zA-Z0-9]#', 'title_callback', $title);}
// the callback function for title
function title_callback ($matches) 
{        
    return $matches[3].' '.$matches[2].' '.$matches[1];
}
Find in same file:
Code:
[COLOR=#000088][FONT=Consolas]$title[/FONT][/COLOR][COLOR=#339933][FONT=Consolas]=[/FONT][/COLOR][COLOR=#000088][FONT=Consolas]$db[/FONT][/COLOR][COLOR=#339933][FONT=Consolas]->[/FONT][/COLOR][COLOR=#004000][FONT=Consolas]safesql[/FONT][/COLOR][COLOR=#009900][FONT=Consolas]([/FONT][/COLOR][COLOR=#000088][FONT=Consolas]$title[/FONT][/COLOR][COLOR=#009900][FONT=Consolas])[/FONT][/COLOR][COLOR=#339933][FONT=Consolas];
[/FONT][/COLOR]
Replace with
Code:
[COLOR=#000088][FONT=Consolas]$title[/FONT][/COLOR][COLOR=#339933][FONT=Consolas]=[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] [/FONT][/COLOR]my_clean_title[COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000088][FONT=Consolas]$db[/FONT][/COLOR][COLOR=#339933][FONT=Consolas]->[/FONT][/COLOR][COLOR=#004000][FONT=Consolas]safesql[/FONT][/COLOR][COLOR=#009900][FONT=Consolas]([/FONT][/COLOR][COLOR=#000088][FONT=Consolas]$title[/FONT][/COLOR][COLOR=#009900][FONT=Consolas]))[/FONT][/COLOR][COLOR=#339933][FONT=Consolas];
[/FONT][/COLOR]


Open /engine/modules/addnews.php
Copy the above function at end of file

Find in same file:
PHP:
$title = $db->safesql( $parse->process( trim( strip_tags ($_POST['title']) ) ) );
Replace with
PHP:
$title = my_clean_title($db->safesql( $parse->process( trim( strip_tags ($_POST['title']) ) ) ));

I have not tested.....
 
hm, For two spaces you can try to remove one of space between commas in title_callback function and see if works, .' '. to .''.
 
I tried to .''. but when all the words are his own, are not separated by any space.
I am glad to work and so with two spaces between words, saved me a lot of work ;)
 
Hi sir,

I changed the /engine/inc/addnews.php and /engine/module/addnews.php
I changed this code:
return $matches[3].' '.$matches[2].' '.$matches[1];
with:
return $matches[3].''.$matches[2].''.$matches[1];
If I understood well, but does not work
I appreciate the effort and your answers. Thanks
 
Hi sir,

I changed the /engine/inc/addnews.php and /engine/module/addnews.php
I changed this code:

with:
return $matches[3].''.$matches[2].''.$matches[1];
If I understood well, but does not work
I appreciate the effort and your answers. Thanks


Try this first:
return $matches[3].''.$matches[2].' '.$matches[1]

if not work try this:
return $matches[3].' '.$matches[2].''.$matches[1]

 
Last edited:
Status
Not open for further replies.
Back
Top