Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:09:58+00:00 2026-06-14T19:09:58+00:00

I want to transform a webpage into leet (1337) speak with XPath and PHP.

  • 0

I want to transform a webpage into leet (1337) speak with XPath and PHP.

It can be done with only PHP but then the HTML nodes are also replaced with leet speak.

Example ($html is the webpage):

$find = array("a","b","c","d","e","f","g","h","i","j"."k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$repl = array("4","b","c","d","3","f","g","h","1","j","k","1","m","n","0","p","9","r","5","7","u","v","w","x","y","2");
$html = str_replace($find, $repl, $html);

That replaces also the HTML nodes.

Can this be done with XPath and PHP with the XPath selector text()? Example ($html is the webpage):

$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$xpath->query('//text()');
\\HERE THE REPLACING IN XPATH
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:10:00+00:00Added an answer on June 14, 2026 at 7:10 pm

    Try this:

    $dom = new DOMDocument;
    $dom->loadHTML( $html );
    $xpath = new DOMXPath( $dom );
    $nodes = $xpath->query( '//text()' );
    foreach( $nodes as $node )
    {
        $node->nodeValue = str_replace( $find, $repl, $node->nodeValue );
    }
    echo $dom->saveHTML();
    

    Note that this is probably a more useful xpath query for your needs:

    $nodes = $xpath->query( '//head/title/text() | //body//text()' );
    

    … as this will only replace text in <head><title> or text being descendants of <body>. Probably wouldn’t want to replace possible styles, Javascript and what have you. 😉


    On a side note: I’ve tested this with your arrays of find and replace characters, but there’s something fishy going on with them, that I can’t figure out. The replacement characters don’t seem to line up with the found characters all the time. I have no idea why that is.

    I’ve recreated the arrays, and these work for me:

    $find = array('a','b','c','d','e','f','g','h','i','j'.'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
    $repl = array('4','b','c','d','3','f','g','h','1','j'.'k','1','m','n','0','p','9','r','5','7','u','v','w','x','y','2');
    

    I just can’t figure out why your arrays are not working for me. :-/ Perhaps an encoding issue? If anybody want to chime in and venture a guess, please do.

    Edit: As rxdazn noticed, "j"."k" was the problem in the first array, which I totally overlooked as you can see from my recreated arrays (I copied $find over to $repl, replaced quotes, and filled in the leet characters).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to transform some xml into HTML that has the following format: <TR><TD>
I want to transform the following url: http://localhost/index.php?foo=bar&bar=foo Into: http://localhost/index/bar/foo In other words I
I want to transform a List[Option[T]] into a Option[List[T]] . The signature type of
I want to transform in Python 2d arrays/images to polar, process then, and subsequently
This is my Xml file.i want to transform this xml file into another customized
I've got an array of channels that I want to transform into a single
I want to transform an XML file with javax.xml.transform.Transformer , but my web access
I want to transform the 'values' array created by xml_parse_into_struct() into a bunch of
In F# I want to transform a list of chars into a string. Consider
I have a web application and I want to transform a xml to html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.