In the lesson, I would like to change the div tag li . But not everyone is just some well defined. In this case, people who have the ID "tab- *" starts, I need to use the PHP function easily: & lt; Div id = "tab-141285" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "tab-85429" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; Get this text
& lt; Li id = "tab-141285" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Li & gt; & Lt; Li id = "tab-85429" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Li & gt; Can you advise me?
Thanks
Regular expressions for parsing HTML are not sufficient I Any regex trying to use will be fragile. Instead, I suggest this.
This idea is:
- all
& lt; Div & gt; Find elements that start with a id attribute "tab -" // div [starts (@id, " Tab - ")] - For each of them, a new
& lt; Li & gt; element. - All
& lt; Div & gt; -
-
-
-
-
-
-
- Li> >.
Because there is no basic element in your string, we will dance a little bit before we put it in one and then make it again.
Example: $ html = & lt; & Lt; & Lt; 'Html' & lt; Div id = "tab-141285" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "tab-85429" class = "my-class" & gt; & Lt; Div class = "my-subclass" & gt; & Lt; Div & gt; Advertising Ready Advertising & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; Html; $ Dom = new DOMDocument (); $ Dom- & gt; Load HTML ("& lt; div> $ html ", LIBXML_HTML_NOIMPLIED); $ Xpath = new DOMXPath ($ dom); $ Node = $ xpath- & gt; Query ('// div [Start-start ('id,' tab- "]] '); Foreign currency ($ node $ as node) {$ li = $ dom- & gt; Create element (' li ' ); While ($ node-> attribute-> length) {$ li-> SetAttiInode ($ node-> Attribute-> Item (0));} while ($ node- & First Child) {$ li-> Epand Chલ્ડ ($ node-> First Child);} $ Node-> parentNode-> Infant ($ li, $ node);} $ Html = ''; Foreign currency ($ dom- & gt; document element-> child nodes $ node form) {$ html. $ = $ Dom-> Save HTML ($ node);} $ Html echo; < / Code>
OU Put: - li id = "tab-141285" class = "my-class">
& gt; Lt; div & gt; Ads Ready for Advertising & lt; / div & gt; & lt; / div & gt; & lt; / li & gt; & lt; li id = "tab-85429" class = "My-class">
Ad ready to ad & lt; / div & gt; & lt; / div & gt;
Popular posts from this blog
I'm trying to call the Python using the Java program py4j . I've been installing the plug-in Eclipse and test name Piidvi project. I'm trying to execute the following part of the code found on py4j webpage: Import from py4j.java_gateway to JavaGateway, java_import gateway = JavaGateway () jvm = gateway.jvm java_import (jvm, '' Org.eclipse Kkorkrisorsej. * ") Vrkspes_rut = Jvankresourkesplginkgetvrkspas (). GetRoot (Gateway .help (workspace_root, '* Projects *') project_names = [project.getName () (for projects workpace_root.getProjects))] print (Projekt_nam) But I There is an error in import. I have checked that the P4JJ is present in the Jar Eclipse plugin directory. Can anyone help please? I had to install the py4j application
I am new to Python I am trying to parse JSON result from a URL. Basically, I was using the following: response = urllib.request.urlopen (url) json_obj = json.load (response) It should be a stroke "str 'not' bytes' in the lines of a given" JSON object, so after searching on the StackoverView Flo, I decode the response in this way: F = urllib.request.urlopen (Url) charset = f.info (). Get_param ('charset', 'utf8') data = f.read () decoded = json.loads (data.decode (charset)) If I print "decode" I is as follows: { 'link': { 'summary data': 'https: // localhost / piwebapi / streams / p0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE / summary' 'value': 'https: // localhost / Piwebapi / streams / P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTExNQU42NDIwXFNJTlVTT0lE / price ',' InterpolatedData ':' https: // localhost / Piwebapi / streams / P0_7qHaW4UHU-RlCaz8tpasAAQAAAAU0hJTE...
I am developing a GUI for the current script, which expects some straight values in the base workspace. The GUI will move users' values to the base-workspace and then the script will start and close itself immediately. It sounds very easy and has values that run with Essenin and Evelyn, but I work for days with the problem that if the script takes the values of my post, then I get a message: Try to add var_name View MATLAB programming for static workspace details, see restrictions on assigning at variables. What's the problem? The GUI is closed and the script will use the base-workspace without restriction. How can this be done? The script is untouchable (not mine) and this base expects variables in the workspace, so the GUI is moving the value in the workspace and nothing else. A stable workspace is not required Workspaces will be free of any restrictions. To summarize: I want to delete "Static" in the "static workspace" Specifies the...
Comments
Post a Comment