NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Converting a line to a PHP string?


Joined: 07 Jun 2006
Posts: 6
Reply with quote
Hi

Just wondering if it's possible to highlight a line, for example:

Code:
<table cellpadding="0" cellspacing="0" border="0">


And then have it converted to a PHP string (with the quotes escaped) and even an echo at the beginning of the line?

Code:
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";


Or even have it preceed the text with a configurable value, for example, $text .=

Code:
$text .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";


What do you reckon?

Thanks in advance
M
View user's profileFind all posts by themitchSend private message


Joined: 15 Jul 2006
Posts: 18
Reply with quote
I did this for 4.6.4615

Code:
<?php
/**
* @version $Id: returnEscaped.php 223 2006-07-15 08:55:59Z danial $
* @license Released as Public Domain
**/

/*
* Returns en escaped string back
*
* */
class ReturnEscaped
    {
    var $text;

    function run()
        {
        // Needed because file doesn't work with php://stdin
        $this->text=explode("\n", rtrim(file_get_contents('php://stdin')));
        $this->walkA();

        echo utf8_decode(implode("\n", $this->text));
        }

    function walkA()
        {
        for ($i=0; $i < count($this->text); $i++)
            {
            $this->text[$i]='<?php echo "' . addslashes($this->text[$i]) . '";?>';
            }
        }
    }

$ae=new ReturnEscaped;
$ae->run();
?>

_________________
developer@ clexus
View user's profileFind all posts by danialtSend private message


Joined: 07 Jun 2006
Posts: 6
Reply with quote
Hi danialt

Looks interesting but how would I use it/implement it in the IDE?

Thanks
Martin
View user's profileFind all posts by themitchSend private message


Joined: 15 Jul 2006
Posts: 18
Reply with quote
http://forum.nusphere.com/some-useful-scripts-for-phped-t1989.html

command : @php5@ -q "c:\returnEscaped.php"

you can even assign a shortcut to it Smile

_________________
developer@ clexus
View user's profileFind all posts by danialtSend private message


Joined: 07 Jun 2006
Posts: 6
Reply with quote
Ok, I tried that, but doesn't quite work.

I created the script, saved it as ReturnEscaped.php, then went to Tools -> Settings -> Integration, added a new menu, set "Execute with" to Shell, and "Command line:" to @php5@ -q "c:\wamp\www\ReturnEscaped.php"

In the options I only checked-on the "Show this command in Tools menu"

Then, when I highlighted some text in a file, and hit Tools -> Scripts -> "Convert to PHP string" I get the following dialog popup:
"Windows cannot find 'C:\program' make sure you typed the name correctly, and then try again. "

Is this to do with Shell? Why can it not seem to shell out successfully? Is there a path I'm supposed to set somewhere?

Thanks
M
View user's profileFind all posts by themitchSend private message


Joined: 15 Jul 2006
Posts: 18
Reply with quote

_________________
developer@ clexus
View user's profileFind all posts by danialtSend private message


Joined: 11 May 2006
Posts: 20
Reply with quote
How about extending the Integration with some sort of "easy Plugin" architecture? I mean the possibility to use PHP scripts for certain actions is really a superb feature, but I think that there are not too many developers using this really cool feature out there. I guess there is much more potential in this easy architecture. For example: How about creating a simple "Plugin" Format which basically is a PHP script but has a detailed header (e.g. as PHP Comment) which includes all settings that are necessary to plug it into phpEd (essentially all settings in the dialog above) - or a special INI format which includes these settings. With this format adding such a script is just like "selecting the desired file" and the rest can be done automatically. Having such a simple format you could easily start a small "Extension Exchange" were all PHPEd users could start to share their "helper Scripts" and I am sure that many developers will contribute their extensions here.
View user's profileFind all posts by blueendSend private message


Joined: 15 Jul 2006
Posts: 18
Reply with quote
blueend wrote:
How about extending the Integration with some sort of "easy Plugin" architecture? I mean the possibility to use PHP scripts for certain actions is really a superb feature, but I think that there are not too many developers using this really cool feature out there. I guess there is much more potential in this easy architecture. For example: How about creating a simple "Plugin" Format which basically is a PHP script but has a detailed header (e.g. as PHP Comment) which includes all settings that are necessary to plug it into phpEd (essentially all settings in the dialog above) - or a special INI format which includes these settings. With this format adding such a script is just like "selecting the desired file" and the rest can be done automatically. Having such a simple format you could easily start a small "Extension Exchange" were all PHPEd users could start to share their "helper Scripts" and I am sure that many developers will contribute their extensions here.


I agree. You can have probably an XML file attached to the source code of the plugin (php code) which tells what to be done.
e.g. Joomla! extenstion installer :

Code:

<?xml version="1.0" encoding="iso-8859-1"?>
<mosinstall type="component" version="1.0.0">
   <name>Content Page</name>
   <author>Joomla! Project</author>
   <creationDate>July 2004</creationDate>
   <copyright>(C) 2005 Open Source Matters. All rights reserved.</copyright>
   <license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
   <authorEmail>admin@joomla.org</authorEmail>
   <authorUrl>www.joomla.org</authorUrl>
   <version>1.0.0</version>
   <description>This shows a single content page</description>
   <params>
      <param name="pageclass_sfx" type="text" size="20" default="" label="Page Class Suffix" description="A suffix to be applied to the css classes of the page, this allows individual page styling" />
      <param name="back_button" type="list" default="" label="Back Button" description="Show/Hide a Back Button, that returns you to the previously view page">
         <option value="">Use Global</option>
         <option value="0">Hide</option>
         <option value="1">Show</option>
      </param>
      
      <param name="@spacer" type="spacer" default="" label="" description="" />
      <param name="keyref" type="text" size="25" default="" label="Key Reference" description="A text key that an item may be referenced by (like a help reference)" />
      <param name="docbook_type" type="list" default="" label="DocBook Type" description="Associates a type of DocBook document with this content item (Note: experimental, not for production).">
         <option value=""></option>
         <option value="appendix">Appendix</option>
         <option value="article">Article</option>
         <option value="book">Book</option>
         <option value="chapter">Chapter</option>
         <option value="glossary">Glossary</option>
         <option value="part">Part</option>
         <option value="refentry">Refentry</option>
         <option value="section">Section</option>
      </param>
   </params>
</mosinstall>

_________________
developer@ clexus
View user's profileFind all posts by danialtSend private message
Almost there ...


Joined: 07 Jun 2006
Posts: 6
Reply with quote
I'm not sure what's happened, but when I highlight a <table> tag and click on the new script it produces the following:

<?php echo "<\0t\0a\0b\0l\0e\0 \0c\0e\0l\0l\0p\0a\0d\0d\0i\0n\0g\0=\0\"\00\0\"\0 \0c\0e\0l";?>

It's close, but not exactly what I was looking for Wink

Any clues?
View user's profileFind all posts by themitchSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
are you running PhpED 4.0?
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 07 Jun 2006
Posts: 6
Reply with quote
yes, but 4.5, not 4.6, I haven't got round to upgrading yet. Is that a problem?
View user's profileFind all posts by themitchSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7857
Reply with quote
probably yes, at least it explains why it works fine in 4.6 while you're getting extra zeros.
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Converting a line to a PHP string?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic