zc5 Posted June 27, 2013 Share Posted June 27, 2013 I am still a novice with PHP but I feel like I am making this task more complicated then it needs to be. I recently acquired a tool (dumpHTML) that is coded in php which allows me to convert mediawiki content into html. I have been trying to make minor changes to it so it looks more clean after i convert to html. All the titles of my pages end with " - Docwiki" (Example: "Hole Mounts - Docwiki") and i do not like that. I want to write something that deletes the " - Docwiki" at the end of every title once i use the conversion tool. Here is the original code line: <title><?php $this->text('pagetitle') ?></title> Here is what I have attempted and i get a fatal error when i try to run the tool: <?php $pagetitleA=text('pagetitle'); chop($pagetitleA, " - Docwiki"); ?> <title><?php $this->$pagetitleA ?></title> Is there something I am missing or doing completely wrong? Any help or suggestions will be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/ Share on other sites More sharing options...
dalecosp Posted June 27, 2013 Share Posted June 27, 2013 <title><?php echo str_replace("- Docwiki",'',$this->text('pagetitle')); ?></title>? Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438274 Share on other sites More sharing options...
zc5 Posted June 27, 2013 Author Share Posted June 27, 2013 Hmm that looks like it would work but i ran it and im still getting titles with " - Docwiki" at the end of it.... Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438281 Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 Can we see your code where you do the str_replace? Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438283 Share on other sites More sharing options...
DavidAM Posted June 27, 2013 Share Posted June 27, 2013 His original post did not have echo in it. It may be that the text() method is echoing the value rather than returning it. You're going to have to dig deeper to find out where the "pagetitle" value is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438288 Share on other sites More sharing options...
zc5 Posted June 27, 2013 Author Share Posted June 27, 2013 Yes, of course. This is code from the tool i use, I did not write this myself although im trying to make some edits. I barely understand half of it but thank you though! <head> <meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" /> <!-- headlinks removed --> <link rel="shortcut icon" href="<?php $this->text('favicon'); ?>"/> <title><?php $this->text('pagetitle') ?></title> <style type="text/css">/*<![CDATA[*/ @import "<?php $this->text('skinpath') ?>/main.css"; /*]]>*/</style> <link rel="stylesheet" type="text/css" media="print" href="<?php $this->text('stylepath') ?>/common/commonPrint.css" /> <link rel="stylesheet" type="text/css" href="<?php $this->text('stylepath') ?>/common/shared.css" /> <!--[if lt IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE50Fixes.css";</style><![endif]--> <!--[if IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE55Fixes.css";</style><![endif]--> <!--[if IE 6]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE60Fixes.css";</style><![endif]--> <!--[if IE 7]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE70Fixes.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";</style><![endif]--> <!--[if lt IE 7]><?php if( in_array( 'IE', $skin->cssfiles ) ) { ?><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion']; } ?>"></script> <!--[if IE]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script> <meta http-equiv="imagetoolbar" content="no" /><![endif]--> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/jquery.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js"></script> <link rel="stylesheet" type="text/css" media="print" href="<?php $this->text('skinpath') ?>/NavContent.css" /> <link rel="stylesheet" type="text/css" media="print" href="<?php $this->text('skinpath') ?>/CategoryTree.css" /> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/NavContent.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/CategoryTree.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/md5.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/utf8.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/lookup.js"></script> <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('skinpath' ) ?>/highlight.js"></script> <?php if($this->data['jsvarurl' ]) { ?><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl' ) ?>"></script><?php } ?> <?php if($this->data['pagecss' ]) { ?><style type="text/css"><?php $this->html('pagecss' ) ?></style><?php } ?> <?php if($this->data['usercss' ]) { ?><style type="text/css"><?php $this->html('usercss' ) ?></style><?php } ?> <?php if($this->data['userjs' ]) { ?><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('userjs' ) ?>"></script><?php } ?> <?php if($this->data['userjsprev']) { ?><script type="<?php $this->text('jsmimetype') ?>"><?php $this->html('userjsprev') ?></script><?php } ?> <style type="text/css">.highlight { background: #FFFF40; }</style> </head> Line where i want to edit is line 5. I hope i didn't give more then necessary. Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438291 Share on other sites More sharing options...
zc5 Posted June 27, 2013 Author Share Posted June 27, 2013 Ya i have tried to find where the "pagetitle" is coming from and i can't seem to find it.... i can try again if you think that is the main source of the problem. I know somewhere 'pagetitle' is just simply using the mediawiki pagetitle, but i can't seem to find where so i was hoping to alter it after the fact Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438292 Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 I wanted to see where you implemented the suggestion to use str_replace. You don't need that other software to do what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438293 Share on other sites More sharing options...
zc5 Posted June 27, 2013 Author Share Posted June 27, 2013 O ok I understand. My apologies <head> <meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" /> <!-- headlinks removed --> <link rel="shortcut icon" href="<?php $this->text('favicon'); ?>"/> <title><?php echo str_replace(" - Docwiki",'',$this->text('pagetitle')); ?></title> <style type="text/css">/*<![CDATA[*/ @import "<?php $this->text('skinpath') ?>/main.css"; body { font-size:small; } /*]]>*/</style> <link rel="stylesheet" type="text/css" media="print" href="<?php $this->text('stylepath') ?>/common/commonPrint.css" /> <!--[if lt IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE50Fixes.css";</style><![endif]--> <!--[if IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE55Fixes.css";</style><![endif]--> <!--[if IE 6]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE60Fixes.css";</style><![endif]--> <!--[if IE]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script> <meta http-equiv="imagetoolbar" content="no" /><![endif]--> All i did was replace the two lines: <title><?php echo str_replace(" - Docwiki",'',$this->text('pagetitle')); ?></title> <title><?php $this->text('pagetitle') ?></title> Is this what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438295 Share on other sites More sharing options...
Solution AbraCadaver Posted June 27, 2013 Solution Share Posted June 27, 2013 Well it would be best to look through the class and find the text() function to see how to modify it, but quick and dirty this should work. Replace: <title><?php $this->text('pagetitle') ?></title> With: <title><?php ob_start(); $this->text('pagetitle'); echo str_replace(" - Docwiki", "", ob_get_clean()); ?></title> Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438301 Share on other sites More sharing options...
zc5 Posted June 27, 2013 Author Share Posted June 27, 2013 IT WORKED! Thank you so much guys! I am interning at a company and i was tasked to do this and cannot figure it out. They know I am not super experienced with php so this helped so much and really impressed my manager! Many many many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/279643-how-can-i-remove-part-of-a-title/#findComment-1438305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.